Comp 110 – Intro to Programming

University of North Carolina at Chapel Hill

Program 3

Happy / Wild

  • Assigned: Fri 1/25
  • Due: Fri 2/1
  • Total possible points: 1

Description

Your program will ask the user whether they are feeling Happy or Wild. The user will type in their response. Depending on the response, your program will display the respective happy face (from listing 1.2) or wild face (from Assignment 2).

The output in your console should look similar to

  > Are you feeling happy or wild?
  > happy
        

The Happy face is drawn in the Applet (i.e. the graphics window), and the program stops.

Some tips:

  • Start by copying the skeleton. Follow the implementation plan provided.
  • To read the users response, create a keyboard variable. Then, include this line: String response = keyboard.nextLine(); "nextLine( )" will read all characters typed. As in program 1, hit the Enter key to signal the end of the input from the user.
  • Remember that when dealing with strings, comparison is performed by response.equals(“happy”), not the == as with integers.
  • Capitalization mattes. Your code should accept “happy” and “Happy”, as the same response, but not other capitalizations such as "HAppy", "HAPPY", etc..
  • Your program should only show one face every time it is run. If you know what a loop is, do not use one.
Watch out for these:
  • Remember that Eclipse is in charge. Sometimes, closing your applet using the “X” button will not work. The best way to close an applet in this case is to directly stop execution from within Eclipse. The tool bar just above your Console window contains a red square. Click it to stop your program (which automatically closes the Applet window).
  • If you are running Windows, make sure you size and position the Eclipse window so that it does not overlap with the Applet window that displays in the upper left hand corner of your screen. There is a bug in Windows where if your Applet gets hidden, you will lose what you have drawn in the Applet window. This is hard to explain in words, but try it and you will see what happens.

Requirements

Turn in the following:

  • Print out your code and submit it in class following the general guidelines.
    • Remember to include a cover sheet..
    • Implementation plan, test plan, and output are not required for this assignment.
    • You do not have to turn in a screen shot of your Applet output (i.e. the face). Just your Java code.
    • Your code does not have to include your implementation plan (this is given to you above) or a test plan.
  • Submit your code to Sakai.

Objectives

Write your first program on your own. Use an if statement.