time due | submission file |
---|---|
11:00 PM Friday 30 November, 2007 | csci/201/Homework6 |
At exactly 11:00 PM, on Friday, 30 November, 2007, a program will be run to copy your homework out of your csci/201/Homework6 directory on the UNCA Computer Science server. Your homework must be stored in this directory exactly as specified a bit later in this handout in order to be copied. Programs that are not stored correctly will not be graded and will be considered unsubmitted.
At 11:00 PM on each of the three days following 30 November, additional attempts will be made to copy programs that are submitted late. There is a penalty of 15% for each day a program is submitted late.
In assignment 3,
you wrote a program to generate ASCII art in the form of psuedo-police sketches.
In this assignment, you will turn that program into a class called
Head
and then use that class to create a totem pole. Here are the details.
In assignment 3, you prompted the user to choose among options for each characteristic that defined the appearance of a face. The user specified each choice with an integer number. For example, the hair style characteristic might have been specified as follows:
Choices of hair style 1) parted 2) curly 3) balding Enter choice: 2
In the Head
class, instance variables will be used to store the values of the facial characteristics. The values of
the instance variables are set by constructors. Here is a possible
template for the Head
class:
public class Head { // instance variables private int hairStyle; private int eyeStyle; private int mouthStyle; // methods public Head() // the no-input constructor that assigns default values to the 3 instance variables public Head(int myHair, myEyes, myMouth) // the constructor that sets the values of the 3 instance variables equal to the respective parameters public void setHair(int newHairValue) // a mutator method to change the value of the hairStyle instance variable public void setEyes(int newEyeValue) // a mutator method to change the value of the eyeStyle instance variable public void setMouth(int newMouthValue) // a mutator method to change the value of the mouthStyle instance variable public void drawHair() // a method that draws the hair specified by the instance variable hairStyle public void drawEyes() // a method that draws the eyes specified by the instance variable eyeStyle public void drawMouth() // a method that draws the mouth specified by the instance variable mouthStyle public void drawFace() // a method that draws the complete face by calling drawHair(), drawEyes(), and drawMouth() }
You may use other facial features besides hair, eyes, and mouth to characterize your head. You may also use more than three features, but be sure to include an instance variable and the methods needed to set and draw each feature that you use. Your class also need to assign useful default values for all its features.
In the method main()
, you will use the Head
class to create the heads of a totem pole. You will first prompt the
user to enter the number of heads to display in the totem pole. You will then create an array of Head
objects of the specified size. Here is some example code to help you with that task.
// create the array Head[] totempole = new Head[4]; // initialize the array for (int i=0; i<totempole.length; i++) { totempole[i] = new Head(); }
The code above must be changed in 2 ways when used in your program:
Head
because the features of the Head
s
in your totempole must vary. They can not all be identical.The final step in your program is to draw the totempole. The output might look something like the following for a three head totem pole.
@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@ | | | | | (*) (*) | | | _| |_ |_ _| | |______| | | | ^^^^^^^^^^^^^^^^ | ^^^^^^^^ | | ^^ | | -- -- | | + + | _| |_ |_ _| | '''''' | | <====> | | | @@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@ | | | | | (*) (*) | | | _| |_ |_ _| | (|||) | | |
Remember to adhere to the style guidelines specified in assignment 2.
Your completed program must be stored within a subdirectory csci/201/Homework6 of your Linux home directory. Your project src directory will contain two files: Main.java and Head.java.
If you complete this assignment on your "home" system,
you still must:
(1) create a Homework6
project;
(2) accept the defaults when creating your project thus
creating a program with a Main
class within
the homework6
package;
(3) add the Head class to the homework6
package;
(4) create a csci/201/Homework6
directory within your Linux account to store your work; and
(4) copy src/homework/Main.java
and src/homework/Head.java
of your Homework6
project at home into your
csci/201/Homework6 directory at UNCA.