import javax.swing.JApplet; import java.awt.Graphics; import java.util.Scanner; /** * Kye Hedlund Sample Solution to Program 3 Comp 110 Spring 2013 * * Implementation Plan Grow your program one small step at a time. * 0. Define a * happyFace method and display it. * 1. Read user input. Echo it (print it out). * 2. Modify your program so that a happy face is displayed only if the user * responds 'happy' * 3. Define a wildFace and display it. * 4. Modify the program * so that a wild face is displayed if the user does not respond 'happy' * 5. Modify your program so that a happy face is displayed if the user enters * "Happy". * * Test Plan * 1. Run once with input "happy". Expect HappyFace. * 2. Run a second * time with input "wild". Expect WildFace. * 3. Run a third time with input * "jlkjl". Expect WildFace. */ public class HappyWild extends JApplet { public void init() { setSize(500, 500); } public void paint(Graphics canvas) { System.out.println("Are you feeling happy or wild?"); Scanner keyboard = new Scanner(System.in); String response = keyboard.nextLine(); System.out.println("response = " + response); if (response.equals("happy") || response.equals("Happy")) { canvas.drawOval(100, 50, 200, 200); canvas.fillOval(155, 100, 10, 20); canvas.fillOval(230, 100, 10, 20); canvas.drawArc(150, 160, 100, 50, 180, 180); } else { // Draw wild face canvas.drawOval(100, 50, 100, 100); canvas.fillOval(200, 100, 10, 20); canvas.fillOval(230, 100, 20, 20); canvas.drawArc(50, 160, 60, 50, 80, 180); } } }