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. 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. Assume the interest is 0 if the previous balance was 0 but if the previous balance was greater than 0 the interest is 2% of the total owed (previous balance plus additional charges). Assume the minimum payment is as follows:
new balance for a new balance less than $50
$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 the actual dollar amounts in each place using currency format from the NumberFormat class-see Listing 3.4 of the text for an example that uses this class.
CS CARD International Statement
===============================
Previous Balance: $
|
Additional Charges: $ Interest: $
New Balance: $
|
66
Chapter 6: More Conditionals and Loops
Minimum Payment: $
The code below is my answer for this work, but when I compile, it is showing error, which I could not figure what exactly it is.
1 import java.util.*;
2 public class ChargeAccount{
3
4 public static void main(String[] args){
5
6 Scanner scan = new Scanner(System.in);
7 System.out.println("Please enter your previous balance");
8 double prevb = scan.nextDouble();
9 System.out.println("Please enter the total charges");
10 double totalb = scan.nextDouble();
11 double interest;
12 if (prevb==0){
13 interest = 0.0;
14 }
15 else{
16 interest = 0.02*(totalb+prevb);
17 }
18 double newb = totalb + prevb + interest;
19 double minPay;
20 if(newb < 50){
21 minPay = newb;
22 }
23 else if(newb < 300){
24 minPay = 50;
25 }
26 else
27 minPay = newb*(20/100);
28 }
29 System.out.println("Previous balance was: "+prevb);
30 System.out.println("Total charges: "+totalb);
31 System.out.println("Interest is: "+interest);
32 System.out.println("New balance is: "+newb);
33 System.out.println("Minimum pay is: "+minPay);