Lab 09: If-then-else CSCard Lab



We will be expanding on the use of submissions and testing via . This system will also be the means by which you receive feedback and grades for your programs.

Collaboration: You are encouraged to work with another student to complete this lab. Each of you should submit your own copy of the code. It's okay if your files are similar or identical, as long as both of your names are present at the top.


  • Practice validation and if-else-if statements.
  • More autolab submission practice.
  • Submit a program and JUnit tests in a zip archive.

Key Terms

zip file

compressed file that contains one or more files

code coverage

percentage of code that was tested by JUnit tests

problem coverage

percentage of instructor's test cases that passed

Part 1: Understand the Problem

Write a program to prepare the monthly charge account statement for a customer of CS Card International, a credit card company. The program should take as input the previous balance on the account and the total amount of additional charges during the month. It should then compute the interest for the month, the total new balance (i.e., the previous balance plus additional charges plus interest), and the minimum payment due.

  • The interest is $0 if the previous balance was $0.00 or less. If the previous balance was greater than $0, the interest is 2% of the total owed (i.e., previous balance plus additional charges).
    EXAMPLE: If the previous balance is $50.00 and the additional charges are $50.00, the interest would be $2.00. But if the previous balance is $0.00, the interest is $0 no matter what.

The minimum payment based on the table below:


  •              $0.00          for new balance less than $0
  •      new balance        for new balance between $0 and $49.99 (inclusive)
  •            $50.00          for new balance between $50 and $300 (inclusiive)
  •     20% of the new balance  for new balance over $300

    EXAMPLE: If the new balance is $38.00 then the person must pay the whole $38.00; if the balance is $128 then the person must pay $50; if the balance is $350 the minimum payment is $70.

Make sure you understand the calculations before trying to program. Write the algorithm in pseudocode on paper, and test your algorithm with some examples to see how it works.

Part 2: Program the Solution

Much of the solution including output formatting has already been done for you. Use the variables provided and keep all output statements exactly as they are.

  1. Download a copy of and as a starting point. Fill in the Javadoc comment for, but don't worry about writing other comments for this lab.
  2. Get the provided code to compile. Write stubs for the calculateInterest and calculateMinPayment methods, returning bogus values for interest and minimum payments for now.
  3. Using the variables provided, code the input statements as described in You must ensure that the program will not crash if the user enters a bad value (i.e., use hasNextDouble). 
  4. Code the rest of the main method as if the two calculate methods were finished, and then test your program. You should see that the code properly reads in a value for the balance and additional charges and outputs the values in the correct format. (The numbers should be wrong until you finish your coding.)
  5. For each calculation (interest and minimum payment), you should code the corresponding method. Run the provided JUnit test cases to make sure your implementation is correct.
  6. Complete the test file by adding additional cases to test each of the two calculation methods. Test the program with a variety of data. Include positive balance, negative balance, and 0 balance.
  7. When you are sure that your code is working properly, run the main method using a variety of inputs (like you used in your examples on paper). Make sure the output still looks okay.

Back to Top