The issues with this program are:
1. File: D:\Unit 3 Data Type, Objects, Assignments\CreditCardBill.java [line: 20]
Error: Type mismatch: cannot convert from double to int
2. File: D:\Unit 3 Data Type, Objects, Assignments\CreditCardBill.java [line: 21]
Error: Type mismatch: cannot convert from double to int
EDIT: I have tried type casting, but I believe you somehow can't go from a double to an int, but instead only the other way is possible. Added a few more variables which I was missing.
Say that you owe the credit card company $1000.00. The company charges you 1.5% per month on the unpaid balance. You have decided to stop using the card and to pay off the debt by making a monthly payment of N dollars a month. Write a program that asks for the monthy payment, then writes out the balance and total payments so far for every succeeding month until the balance is zero or less.
For each month, calculate the interest due on the unpaid balance. Then calculate the new balance by adding the interest and subtracting the payment.
Your output should look like this:
Enter the monthly payment: 100
Month: 1 balance: 915.0 total payments: 100.0
Month: 2 balance: 828.73 total payments: 200.0
Month: 3 balance: 741.16 total payments: 300.0
Month: 4 balance: 652.27 total payments: 400.0
Month: 5 balance: 562.06 total payments: 500.0
Month: 6 balance: 470.49 total payments: 600.0
Month: 7 balance: 377.54 total payments: 700.0
Month: 8 balance: 283.21 total payments: 800.0
Month: 9 balance: 187.46 total payments: 900.0
Month: 10 balance: 90.27 total payments: 1000.0
Month: 11 balance: -8.38 total payments: 1100.0
I have attempted to do this program as follows:
import java.util.Scanner;
class CreditCardBill{public static void main (String[] args){ Scanner input = new Scanner(System.in); int month = 1; month++; System.out.println ("Enter the monthly payment: "); int pay = input.nextInt(); pay++; int left = 1000; double interest = 1.5; int balance = (left + interest); int nbalance = (balance + interest) - pay; while (nbalance >=1) { System.out.println ("Month: "+ month + "Balance: " + nbalance + "Total Payments: " + pay); }}}
Any help with this program is greatly appreciated. Thanks!