Whatz up yoo!
JAVA CODE
//Ex7_7 program import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class Ex7_7 extends Applet implements ActionListener { Label prompt; Button rock, scissors, paper; int roc, scisso, pap, c, ch; public void init() { prompt = new Label ("Make a choice"); add(prompt); rock = new Button("ROCK"); rock.addActionListener(this); add(rock); scissors = new Button("SCISSORS"); scissors.addActionListener(this); add(scissors); paper = new Button("PAPER"); paper.addActionListener(this); add(paper); } public void paint( Graphics g) { int com = 0; ComputerChoice(); switch ( c ) { case 1: com = 1; // 1 reps rock g.drawString("Computer chose rock",50,50); break; case 2: com = 2; // 2 reps scissors g.drawString("Computer chose scissors",50,50); break; case 3: com = 3; // 3 reps paper g.drawString("Computer chose paper",50,50); break; } if( ch == com) g.drawString(" draw ",50,80); else if((ch == 3) && (com != 2 )) g.drawString(" You have won", 50,80); else if((ch == 2) && ( com != 1)) g.drawString(" You have won", 50, 80); else if((ch == 1) && ( com != 3)) g.drawString(" You have won", 50, 80); else g.drawString(" Losser! ", 50, 80); } public void actionPerformed(ActionEvent e) { if(e.getSource() == rock) { ch = 1; } else if(e.getSource() == scissors) { ch = 2; } else { ch = 3; } repaint(); } private int ComputerChoice() { c = 1 + (int) ( Math.random() * 3); return c; } }