Reputation: 15
I have been trying to make a simple program in eclipse for a school project, but I keep getting this after I enter my interest rate. I am relatively new to coding and programming in general, and java is new to me as of this month so any help is appreciated. The code is this:
import java.util.Calendar;
import java.util.Locale;
import java.util.Scanner;
public class Interest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
//Input ============================
System.out.println("Initial loan total:"); //cost
String cost;
cost = in.nextLine();
System.out.println("Down payment:"); //down
String down;
down = in.nextLine();
System.out.println("Length of term:"); //term
String term;
term = in.nextLine();
System.out.println("Interest rate (decimal form):"); //rate
String rate;
rate = in.nextLine();
int principle1 = Integer.parseInt(cost) - Integer.parseInt(down);
String hundred;
hundred = "100";
int interest = Integer.parseInt(rate) * Integer.parseInt(hundred);
//Output ===========================
Calendar c = Calendar.getInstance();
System.out.format("%tB %td, %tY", c,c,c);
System.out.println("");
System.out.println("The initial cost of the loan is $" + cost);
System.out.println("The down payment is $" + down);
System.out.println("The principle is $" + principle1);
System.out.println("The term is " + term + " months");
System.out.println("The interest rate is " + interest + "%");
System.out.println("The monthly patments are $");
in.close();
}
}
When I run the program it lets me put in the initial loan, down payment and length of term but as soon as I put in 0.06 for the interest rate it gives me the error message. I would also like to point out that I have a limited understanding of how the math in my code works.
Upvotes: 0
Views: 754
Reputation: 687
the problem is that you are trying to parse 0.06 to Integer and 0.06 is float.
use Float.parseFloat(rate);
and your interest should be a float too float interest
Upvotes: 2