Design/project08.txt
.edu.INSTITUTION.USERNAME.hotj.project08
.edu.INSTITUTION.USERNAME.hotj.project08
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 #8.1: Write a program that will read a sequence of numbers from the keyboard, and display the minimum, maximum, average, and range of the entered values. Make the input step "foolproof".
It is tricky writing good unit testing for this project, so write a really good driver.
Project #8.2: Add a
factorial()
operation to theCalculator
class that, given an integer n, computes n! = 1 * 2 * ... * (n-1) * n. This new function can safely ignore the second operand.Add new tests to the
CalculatorTest
class for the new function. Also adapt your driver (as necessary) to access the new computation.
Project #8.3: Redesign
Calculator#power()
so that it handles negative exponents (i.e., x^-n for n > 0 is the same as 1/x^n).Add new tests to the
CalculatorTest
class for the new function. Also adapt your driver (as necessary) to access the new computation.
Project #8.4: Add a function to the
Calculator
class to compute the 3n+1 problem. The first operand in the calculator should be taken as n; ignore the second operand. Compute a new value for n as follows:
- If n is even, let n be n/2.
- If n is odd, let n be 3n+1.
Repeat until you reach n=1. The
Calculator
should return how many times n is changed. (n=1 changes n 0 times; n=2 changes n 1 time.)Add new tests to the
CalculatorTest
class for the new function. Also adapt your driver (as necessary) to access the new computation.
Project #8.5: Write a
UnitedStatesOfAmericanFlag
class with no instance variables. The purpose of this class is to generate the U.S. flag in ASCII art (although, since Java uses Unicode instead of ASCII, perhaps it's better to call this "Unicode art").Write three ASCII art methods:
generateASCIIArt()
which returns aString
of the whole flag. Use the next two methods!* * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX * * * * * * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX * * * * * * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX * * * * * * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX * * * * * * * * * * * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXgenerateStripe(n,ch)
that displaysn
consecutivech
characters (e.g.,printStripe(5,'X');
should displayXXXXX
.)generateAlternating(n,ch1,ch2);
that displaysn
consecutive pairs of the charactersch1
ch2
(e.g.,printAlternating(3,'X','Y');
should displayXYXYXY
.)Draw your picture efficiently (i.e., using loops to minimize the number of statements). Feel free to create additional methods that simplify drawing your particular flag.
Unit test all three methods (plus your additional methods). Write a driver that displays the flag.
Write an OCD for the
generateStripe(n,ch)
method.
Project #8.6: Build a "police sketch artist" program as described in Project #7.1, but write a dynamic program that lets the user experiment with different combinations of facial parts in a single execution.
Start with the
Face
andFaceInput
classes as described in Project #7.1. YourFaceCLIDriver
for this project is more elaborate/useful.This driver starts with a 'blank' face and allows the user to modify this face using a two-level menu system.
- The first level of the menu system is implemented in the driver itself, and it allows the user to select which facial part they want to modify (i.e., a menu of menus).
- The second level is implemented in the
FaceInput
class as described in Project #7.1 (mostly, see below).Both menu levels should be implemented in loops which require the user to explicitly quit that particular menu. Also, the face should be printed out just before the menu choice is made.
Reuse the
Menu
class from the lab exercise to greatly reduce your work.Run your test-case class (of course); run the driver at least twenty times as part of your sample execution. Be sure to demonstrate strange situations: what if the user quits a menu right away? what the user enters in bad data? how often can the user enter in bad data? how fast can you construct an interesting face (i.e., with the least input)? how long can you spend constructing a face?
Project #8.7: Use the
Fraction
class from Lab #6 to create a "drill" program that generates random fractions (using classjava.util.Random
), that grade-school students can use to practice their fractional arithmetic.Be sure to include the unit testing from that lab, and this project will add a new driver.
Turn the following things:
Lab Home Page | Prelab Questions | Lab Exercise | Homework Projects