CS 139 Algorithm Development
Lab: Practice with If/else


Objectives

After this lab, students will be able to use a java if/else statement and either nested if statements or compound conditions.

Students will also "white box" test their application.

Background

CS Card International is a credit card company which produces charge statements for its customers each month. This program will generate the appropriate statement amounts.

New Terms

No new terms in this lab.

Materials

Use CSCard.java as a starter for Part 3.

Submission

  • Complete the CodeBat exercises indicated below at http://codingbat.com. Be sure to include your instructor in your profile.
  • Submit CSCard.java via Canvas

Acknowledgment

Adapted from a lab from the original textbook for the course.

Grading

The CS Credit Card part of the lab is the only part that will be graded. The CodingBat exercises are practice and will help you with your coding, but will not be graded.



Part 1 - Set Up
  1. Create a new folder for this lab, on your Desktop or removable drive.

  2. Download the following files to your folder from Canvas.



Part 2 - Warmup

CodingBat is a web site that has practice programming problems. These are set up as individual methods. See the About page for more information.

  1. Go to www.codingbat.com. If you have not already done so, create an account (upper right hand part of the window). Log in and then go to Prefs. Fill in your name and then "Share" your account with your instructor by putting her/his e-mail address in the Share box.

  2. In Java Warm-Ups-1, do problems icyHot and loneTeen. You may submit these problems any number of times to get a clean run.



Part 3 - Charge Account Processing 


Write a program to prepare the monthly charge account statement for a customer of CS CARD International, a credit card company.

The program should prompt for and read the previous balance on the account and the total amount of additional charges during the month (Use the prompts provided for you). The program should then compute the interest for the month, the total new balance (the previous balance plus additional charges plus interest), and the minimum payment due. Use CSCard.java as the starting point for your program. CSCard had several methods in it, so be sure to review all of the methods before you get started. CSCardDriver.java is intended to run the CSCard.java application when you are finished.

Assume 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 (previous balance plus additional charges). 

Calculate the minimum payment based on the table below:

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


So 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 (20% of 350). The program should print the charge account statement in the format below. Print all amounts using the currency format.  (NOTE: formatting has been done for you.  Use the variables provided and keep all output statements exactly as in the .java file).


CS CARD International Statement
===============================

Previous Balance: $
Additional Charges: $
Interest: $

New Balance: $

Minimum Payment: $
Make sure you understand how the calculations are done yourself before trying to program. Write the algorithm in psuedocode and test your algorithm with some data to see how it works.  Use at least four different examples to use for testing.  You want to be able to test each of the conditions shown above.
  1. Using the variables provided, code the input statements as described in CSCard.java.  You must insure that the program will not crash if the user enters a bad value.

  2. Finish the stubs for the calculateInterest() and calculateMinPayment() methods, returning bogus values for interest and minimum payments for now.

  3. Code the rest of the main method as if the two calculate methods were finished and test. You should see that the code properly reads in a value for the balance and additional charges and ouputs the values in the correct format. NOTE: The numbers will be wrong until you finish your coding.

  4. For each calculation (interest and minimum payment), you should code the corresponding method.

  5. Complete the CSCard_Test.java file by adding additional cases to test each of the two calculation methods.
    Test the program with a variety of data. Include debit balance, credit balance, and 0 balance.
    Make sure that you test each of the branches of your if statement(s) and the boundary conditions (like 0 and 49.99).

  6. When you are sure that your code is working properly, run the main method using a variety of inputs (like you used in your tests). Make sure the output still looks okay.

Upload three files zipped (CSCard.java, CSCardDriver.java, CSCard_Test) to the WebCAT assignment when finished. Note: WebCAT will run your test cases against your code. To achieve 100% you will need to have test cases for each branch (white box testing).



Part 4 - Cool Down Practice

Return to www.codingbat.com. In Java Logic-1, do squirrelPlay and answerCell.


last update - 03/02/2014 - NLH