CS 140 Introduction to Computer Science

Project #3

(Due: 8/7)

(Total: 100 points)

Important:
- Please read this document completely before you start coding.
- Also, please read the submission instructions (provided at the end of this document) carefully before submitting the project.
- For code organization purpose, you should create a CS140 folder in your ZFS. Inside the CS140 folder, create another folder named Project3 that will contain the programs that you write for this project.

______

Task #1An Internet service provider has three different subscription packages for its customers:

Package A / For $9.95 per month 10 hours of access are provided.
Additional hours are $2.00 per hour.
Package B / For $13.95 per month 20 hours of access are provided.
Additional hours are $1.00 per hour.
Package C / For $19.95 per month unlimited access is provided.

Write a program that calculates a customer’s monthly bill. It should ask the user to enter the letter of the package the customer has purchased (A, B, or C) and the number of hours (integer) that were used. It should then display the total charges. If an invalid package (other than A, B, or C) or invalid number of hours (<0 or > 30*24) is input, the program should display an appropriate error message and stop.

The following are sample interactions that occur when running the program:

gsyoung@fluffy ~ $ java InternetServiceProviderPart1

Enter the customer's package (A, B, or C): a

Invalid package. Enter A, B, or C.

gsyoung@fluffy ~ $ java InternetServiceProviderPart1

Enter the customer's package (A, B, or C): B

Enter the number of hours used: 721

invalid input, please enter number of hours between 0 and 720.

gsyoung@fluffy ~ $ java InternetServiceProviderPart1

Enter the customer's package (A, B, or C): C

Enter the number of hours used: 0

The charges are $19.95

gsyoung@fluffy ~ $ java InternetServiceProviderPart1

Enter the customer's package (A, B, or C): A

Enter the number of hours used: 20

The charges are $29.95

gsyoung@fluffy ~ $ java InternetServiceProviderPart1

Enter the customer's package (A, B, or C): B

Enter the number of hours used: 20

The charges are $13.95

gsyoung@fluffy ~ $ java InternetServiceProviderPart1

Enter the customer's package (A, B, or C): C

Enter the number of hours used: 20

The charges are $19.95

Task #2Write another Java program that will modify the above program so it also calculates and displays the amount of money Package A customers would save if they purchased Packages B or C, and the amount of money Package B customers would save if they purchased Package C. If there would be no savings, no message should be printed. This time the program should (1) use constants to represent the base rates and base hours, and (2) use DecimalFormat class to define format pattern and print total charges and total savings with $ in the front and two digits after decimal point with trailing zeros displayed.

The following are sample interactions that occur when running the program:

gsyoung@fluffy ~ $ java InternetServiceProviderPart2

Enter the customer's package (A, B, or C): A

Enter the number of hours used: 10

The charges are $9.95

gsyoung@fluffy ~ $ $ java InternetServiceProviderPart2

Enter the customer's package (A, B, or C): A

Enter the number of hours used: 20

The charges are $29.95

With package B you would have saved $16.00

With package C you would have saved $10.00

gsyoung@fluffy ~ $ java InternetServiceProviderPart2

Enter the customer's package (A, B, or C): A

Enter the number of hours used: 30

The charges are $49.95

With package B you would have saved $26.00

With package C you would have saved $30.00

gsyoung@fluffy ~ $ java InternetServiceProviderPart2

Enter the customer's package (A, B, or C): B

Enter the number of hours used: 20

The charges are $13.95

gsyoung@fluffy ~ $ java InternetServiceProviderPart2

Enter the customer's package (A, B, or C): B

Enter the number of hours used: 40

The charges are $33.95

With package C you would have saved $14.00

gsyoung@fluffy ~ $ java InternetServiceProviderPart2

Enter the customer's package (A, B, or C): B

Enter the number of hours used: 720

The charges are $713.95

With package C you would have saved $694.00

gsyoung@fluffy ~ $ java InternetServiceProviderPart2

Enter the customer's package (A, B, or C): C

Enter the number of hours used: 100

The charges are $19.95

______

Submission direction:

In your CS140/Project3 directory, create a Java Source Code file named InternetServiceProviderPart1.java for task #1 and a Source Code file named InternetServiceProviderPart2.java for task #2. Your Java program must begin with the comments below and follow the naming and coding conventions posted on CS140 class web.

// your name

// CS140, section 01

// Project 3 – Internet Service Monthly Bill program

// date

Generate a script file project3.txt with appropriate time stamps and the following steps visible:

  1. a pwd to show the current working directory
  2. an ls to show the files in your CS140/Project3 directory
  3. a cat to display InternetServiceProviderPart1.java
  4. compile InternetServiceProviderPart1.java
  5. runInternetServiceProviderPart1 (run your program many times with all of the following test cases in order to show the correctness of your program)

Normal Cases / (A, 50), (B, 50), (C, 50)
Boundary Cases / (A, 0), (B, 720), (C, 0), (C, 720)
(A, 10), (A, 11),(B, 20), (B, 21)
Abnormal Cases / Invalid service package names: a, b, c, D, 2
Invalid hours: -20, -1, 721, 1000
  1. a cat to display InternetServiceProviderPart2.java
  2. compile InternetServiceProviderPart2.java
  3. run InternetServiceProviderPart2 (run your program many times with all of the following test cases in order to show the correctness of your program)

Test Cases / (A, 10), (A, 20), (A, 30), (A, 720),
(B, 20), (B, 30), (B, 40), (B, 720),
(C, 10), (C, 720)

______
Turn in:

- A printout ofproject3.txt, the run using the script command

- Soft copies of the two program files, (using Blackboard)

InternetServiceProviderPart1.java & InternetServiceProviderPart2.java

______
Late submission policy:

As mentioned in the syllabus: “Late programming projects will not be accepted.”
In case if you cannot complete a project by the due date, submit whatever you have completed for partial credit.

1