InterestRate assignment

Download Report

Transcript InterestRate assignment

InterestRate
Create an InterestRate class and InterestRateViewer client class to do
the following:




A person is purchasing an item with their credit card. Launch an input dialog
window and have the user enter a short description of the item they are
purchasing. Remember the JOptionPane.showInputDialog method that we used
in an earlier class?
Have the user input the amount of the purchase (in whole dollars – i.e.
integer) into an input dialog window.
Have the user input (into another input dialog window) the monthly interest
rate they are paying on this purchase. Note that this may include decimal
places (i.e. they would enter 5.75 to represent 5.75%).
Your program should take these values and do the following:
 Calculate the amount the user will be charged in interest if they don’t pay off this
credit card purchase after the first month.
 Print the following information to the console:
You purchased <description of item> for <amount of purchase> dollars.
Your monthly interest rate is <monthly interest rate> %.
You will be charged <interest amount> in interest after the first month.

Test with a few scenarios and print out your code and the results
Integer.parseInt
int Integer.parseInt(String str)




Use the static method parseInt of the Integer
class to convert a string to an integer
This is helpful when prompting a user in an
input dialog window for an integer
The string must be an integer or the program
will throw a NumberFormatException error.
Examples:
String cash = “20";
int dollarAmt = Integer.parseInt(cash);
Java Concepts 4.6 (Strings)
Double.parseDouble
double Double.parseDouble(String str)




Use the static method parseDouble of the Double
class to convert a string to a floating point number
This is helpful when prompting a user in an input
dialog window for a floating point number
The string must be an floating point number or an
integer or the program will throw a
NumberFormatException error.
Examples:
String cash = "19.75";
double cashAmt = Double.parseDouble(cash);
double dollarAmt = Double.parseDouble("20");
Java Concepts 4.6 (Strings)