Introduction to Computer Science

Program 2 (Grading rubric)

Create a Java program to display several faces. Sample output is shown along the left. 

  //////
 | 0 0 |
[|  >  |]
 | \_/ |
  \___/

  //////
 | - - |
[|  >  |]
 | \_/ |
  \___/

  \\\\\\
 | 0 0 | 
[|  >  |]
 | \_/ |
  \___/

You can see that the faces are very similar, differing only in the characters used to draw the hair and eyes. 

You must accomplish these drawings with a single class. Each face should be an object of that class, instantiated with different arguments. You must limit the arguments to strings of length 1! The main program will consist of six statements similar to these (your class must function with statements similar to these):

Face one = new Face("/", "0");
Face two = new Face("/", "-");
etc...
System.out.println(one.toString());
etc...

Note that all faces are created first, then each is displayed using its toString mentod. Of course, you must implement this method. Your faces can be exactly the same as those shown to the left, or you may vary the idea. Just be sure that you allow each Face object to be created with at least two different characteristics.

Hint: Read Advanced Topic 4.4 on page 131.

Experiment

Remove the explicit reference to the toString method so the println statements look like this:

System.out.println(one);

Does the program function any differently? Can you explain what is going on?

Submission instructions

Be sure to follow the Documentation Standards (for this and every program). When you are ready to submit, obtain a printed copy of your program (Face.java). Remember to sign and attach the required Academic Integrity Pledge cover sheet. The printed program must be turned in to your instructor by the start of class on the date the program is due. You must also email a zipped copy of the program (just Face.java) to your instructor. Identify the email with the subject: ICS Program 2 and be sure that your name appears inside the message. The attached zip file must be named as your last name and the program number (example: smith_2.zip). The zip file must contain a folder having the same name (smith_2). The program files (all related files) should be inside this folder. Be sure to email your working solution before the due date! Do not submit non-working programs.

Email addresses: