Design/project07.txt
.edu.INSTITUTION.USERNAME.hotj.project07
.edu.INSTITUTION.USERNAME.hotj.project07
package.Your instructor will assign you one of the problems below. To solve your problem, write a program that reads the necessary information to compute and output the indicated values, as efficiently as possible. Following the pattern in the lab exercise, first, design using OCD. Then code your design in Java using stepwise translation. Test your program thoroughly.
When executing your program to hand in as part of the project, a JUnit test case should test each method at least five times, but the test case itself needs to be executed just once. A driver program should be run at least five times with different inputs each time.
Project #7.1: Write a menu-driven "police sketch artist" driver using ASCII art . The program should use four different menus for:
- hairstyle (e.g., bald, crewcut, curly, wearing a hat)
- eyes (e.g., beady, bug-eyed, glasses, closed)
- nose (e.g., pug, small, medium, large)
- mouth (e.g., puzzled, smiling, bearded, frowning)
Each menu must provide at least three different choices.
----- | | ....... \|||||||/ --------- . . | | (| O O |) (|-0-0-|) (| . . |) | _\ | | ^ | | > | |\___/| | --- | |||-||| ----- ----- ||||| |||Implement this program using two supporting classes.
- The
Face
class will represent faces as objects. This will be a purely computational class, and so it will have no use for the screen or keyboard. Each instance has four attributes: the four components of a face. You will need a mutator method for each attribute which receives anint
to indicate the value for the facial component. (Hint: use constants likeFace.BALD
to make the code more readable!) Write agenerateASCIIArt()
method which returns the ASCII art as aString
. Write unit tests to set faces with various looks and to verify the return-value ofgenerateASCIIArt()
.- Implement a
FaceInput
class which will have oneFace
object as an attribute. You will need four input methods, one for each facial component. Consider thepromptAndSetHair()
method. It should prompt the user with a menu of possible hair styles; it then reads in the user's preferences, and finally sets itsFace
attribute with the user's choice. This class will use the screen and keyboard; it cannot be unit tested.With these two classes, you can write a
FaceCLIDriver
to implement the program described above: using aFaceInput
instance, it will go through each of the four facial components, call the the appropriateFaceInput
method for each component, and then finally genereate the ASCII art from theFace
attribute of theFaceInput
instance.Run the driver at least ten times in your sample execution (as well as the
FaceTest
test-case class).
Project #7.2: Write a class
Year
which has just a year attribute (an integer); a negative number will represent years "Before Christ" ("B.C.").Write a
Year#toString()
method that returns aString
like"A.D. 2005"
and"376 B.C."
.Write a method
Year#isLeapYear()
that returns true if that year is a leap year, and returns false otherwise. A year is a leap year if it is evenly divisible by 4, unless it is divisible by 100, in which case it must also be divisible by 400. That is, 1996 was a leap year because it is divisible by 4 and not 100, 1997 was not a leap year because it is not divisible by 4, 2000 was a leap year because it is divisible by 4 and 400, but 2100 will not be a leap year because it is divisible by 4 and 100 but not 400.Write a JUnit test-case class that thoroughly tests your methods. You do not have to write a driver.
Write an OCD for the
Year#toString()
method.
Project #7.3: Using the
Metric
class you created in lab 4, write a menu-driven driver that permits the user to select and perform any one of the metric conversions available. There's no JUnit test-case class to write.
Project #7.4: Create a
LetterGrade
class whose instances keep track of letter grades F, D, C, B, and A (represented as a singlechar
). Create two constructors: one that receives achar
, and another that receives a real number between 0 and 100. This second constructor should initialize the letter grade appropriately (use a 60/70/80/90 grading scale). It's completely unnecessary to save this numeric score.Write at least two "accessor" methods: one to return the letter grade itself, and another to return a numeric score on a 4 points scale (4.00 for an 'A', 3.00 for a 'B', etc.).
Write a JUnit test-case class to test
LetterGrade
objects and its methods. No driver is necessary.
Turn the following things:
Lab Home Page | Prelab Questions | Lab Exercise | Homework Projects