-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreditCardBill.java
More file actions
39 lines (28 loc) · 1.14 KB
/
CreditCardBill.java
File metadata and controls
39 lines (28 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.Scanner;
import java.text.DecimalFormat;
public class CreditCardBill {
public static void main(String[] args) {
double monthlyPay, totalPay, bal, interst, interstCost;
int month = 1;
Scanner input = new Scanner(System.in);
DecimalFormat numForm = new DecimalFormat();
System.out.println("Enter the beginning balance: ");
bal = input.nextDouble();
System.out.println("Enter the monthly interest: ");
interst = input.nextDouble();
System.out.println("Enter the monthly payment: ");
monthlyPay = input.nextDouble();
totalPay = monthlyPay;
while (bal > 0) {
interstCost = bal / 100 * interst;
bal = bal - monthlyPay + interstCost;
System.out.print("\nMonth: " + month++);
if (month < 11)
System.out.print("\t\t\tbalance: " + numForm.format(bal));
else
System.out.print("\t\tbalance: " + numForm.format(bal));
System.out.print("\t\t\ttotal payments: " + totalPay);
totalPay+=monthlyPay;
}
}
}