Design/project05.txt
.edu.INSTITUTION.USERNAME.hotj.project05
.edu.INSTITUTION.USERNAME.hotj.project05
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 #5.1: Write a driver program that asks the user how many test scores they have, and then reads that many test scores, averages them, and displays the average and a pass/fail grade appropriate for that average (passing is 60 or higher, failing is below 60). The pass/fail determination should be done in a separate method from the driver, and it should be well tested by a test-case class.
Project #5.2: Write a "password protection" method that you can use to guard your programs. When called, this method should ask the user for a password. It should allow the user N tries at entering the correct password, where N is a value received from its caller. If the user enters the correct password, the method returns control to its caller, where execution proceeds as normal. If the user fails to enter the correct password after N tries, then the method should use System.exit(1) to terminate the program. Store your method in a separate module class, so that different programs can share it. Write a driver to test it out.
Project #5.3: Proceed as in Project 5.1, but instead of displaying a pass/fail grade, the program should compute a "normal" letter grade (90-100 = A, 80-89 = B, 70-79 = C, 60-69 = D, <60 = F).
Project #5.4: Write two methods:
sum(n)
that computes the value (1 + 2 + ... + (n-1) + n)factorial(n)
that computes (1 * 2 * ... * (n-1) * n)Your methods should check that the value of
n
is positive; if not, they should throwIllegalArgumentException
s with appropriate error messages.Use loops to compute the results.
Store these methods in their own class. Write a JUnit test-case class; write four test methods to test both methods on both good and bad arguments.
Also write a driver that allows the user to specify the number of times she wants to run your computations and asks the user to specify which computation to execute.
Turn the following things:
Lab Home Page | Prelab Questions | Lab Exercise | Homework Projects