CS 149 Fall 2018 - Instructor: Molloy Sections: 10 and 11

Home
Calendar
Syllabus
Resources
Linux Install

Lab 09: If-then-else CSCard Lab

 

Background

We will be expanding on the use of submissions and testing via https://autolab.cs.jmu.edu . 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.

Objectives

Key Terms

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 minimum payment based on the table below:

 

Min Payment criterion
$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 CSCard.java and CSCardTest.java as a starting point. Fill in the Javadoc comment for CSCard.java, 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 CSCard.java. 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.

Part 3: Autolab Submission

  1. Open a Terminal window and navigate to the directory for your Java files.
  2. Create a new zip archive containing the two Java files using the following commands zip Lab9.zip CSCard.java CSCardTest.java. Recall that you can check your zip file by running unzip -t Lab9.zip to make sure they do not contain any directory prefixes.
  3. Log into https://autolab.cs.jmu.edu using your Autolab username and password.
  4. Click the "Lab9" link (if not already on that page) and then click the "Submit" button next to Lab9.
  5. Browse to the zip file that you just created, then click "Upload Submission."
  6. Double check that the correct files were uploaded and click "Confirm."

Autolab will score your submission based on three criteria: