ShinRa
Companion Cube
- Joined
- Jun 23, 2003
- Messages
- 5,044
- Reaction score
- 84
import java.awt.*;
import javax.swing.*;
public class ExpectedCost
{
public static void main(String[] args)
{
// this is where variable are declared
int confirm; // confirm dialog box
double cost; // original cost of item
double years; // years until item is bought
double Totalrate; // total inflation amount in dollars
double inflateamt; // inflation amount in dollars per year
double inflaterateDec; // inflation rate in decimal form
double inflateratePerc; // inflation rate in percent form
double TotalCost; // total cost of item after inflation
String costStr; // cost in string format
String yearsStr; // years in string format
String inflateStr; // inflation rate in string format
do {
costStr = JOptionPane.showInputDialog(null, "Please type in the cost of the item.");
cost = Double.parseDouble(costStr);
while (cost <= 0)
{
JOptionPane.showMessageDialog(null, "Please enter a number that is more than zero");
costStr = JOptionPane.showInputDialog(null, "Please type in the cost of the item.");
cost = Double.parseDouble(costStr);
}
yearsStr = JOptionPane.showInputDialog(null, "Please enter the number of years until you buy the item.");
years = Double.parseDouble(yearsStr);
while (years <=0)
{
JOptionPane.showMessageDialog(null, "Please enter a number that is more than zero");
yearsStr = JOptionPane.showInputDialog(null, "Please enter the number of years until you buy the item.");
years = Double.parseDouble(yearsStr);
}
inflateStr = JOptionPane.showInputDialog(null, "Please type in the inflation rate percent.");
inflateratePerc = Double.parseDouble(inflateStr);
while (inflateratePerc <= 0)
{
JOptionPane.showMessageDialog(null, "Please enter a number that is more than zero");
inflateStr = JOptionPane.showInputDialog(null, "Please type in the inflation rate percent.");
inflateratePerc = Double.parseDouble(inflateStr);
}
inflaterateDec = inflateratePerc / 100;
inflateamt = cost * inflaterateDec;
Totalrate = inflateamt * years;
TotalCost = Totalrate + cost;
JOptionPane.showMessageDialog(null, "The Total Cost of the item you are buying is $" + TotalCost);
confirm = JOptionPane.showConfirmDialog(null, "Would you like to use this calculator again?");
}while (confirm == JOptionPane.YES_OPTION);
System.exit(0);
}
}
Compile it (if you use java) and try it out. It was the second program I had to do. ALL ON MY OWN!!!