the simple chunk is the second last portion and the compound chunk is te last portion. I appreciate any help yu guys can lend!
public class InterestCalculator extends JPanel {
public JTextField principal, rate, years;
public JLabel display, displayVal;
public double princ, perc, time, power, finAmount;
public String princ1, perc1, time1, curValue;
public InterestCalculator(int width, int height) {
display = new JLabel();
displayVal = new JLabel();
setLayout(new GridLayout(0,6));
JLabel prin = new JLabel("Principal: ");
add(prin);
int fileNameTextFieldLength = 10;
principal = new JTextField(fileNameTextFieldLength);
add(principal);
JLabel prin1 = new JLabel("Rate(Percentage): ");
add(prin1);
int fileNameTextFieldLength1 = 5;
rate = new JTextField(fileNameTextFieldLength1);
add(rate);
JLabel prin2 = new JLabel("Years: ");
add(prin2);
int fileNameTextFieldLength2 = 3;
years = new JTextField(fileNameTextFieldLength2);
add(years);
JLabel spacer1 = new JLabel("");
JLabel spacer2 = new JLabel("");
JLabel spacer3 = new JLabel("");
JLabel spacer4 = new JLabel("");
JLabel spacer5 = new JLabel("");
JLabel spacer6 = new JLabel("");
add(spacer1);
JButton simple = new JButton("Compute Simple Interest");
JButton compound = new JButton("Compute Compound Interest");
add(simple);
add(spacer2);
add(compound);
add(spacer3);
add(spacer4);
add(spacer5);
add(spacer6);
simple.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
time1 = years.getText();
time = Double.parseDouble(time1);
perc1 = rate.getText();
perc = Double.parseDouble(perc1);
princ1 = principal.getText();
princ = Double.parseDouble(princ1);
finAmount = (princ + (princ * (perc/100) * time));
curValue = NumberFormat.getCurrencyInstance().format(finAmount);
add(display);
display.setText("Computed Simple Interest is: " + curValue);
add(displayVal);
displayVal.setText("" + curValue);
}
});
compound.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
time1 = years.getText();
time = Double.parseDouble(time1);
perc1 = rate.getText();
perc = Double.parseDouble(perc1);
princ1 = principal.getText();
princ = Double.parseDouble(princ1);
power = Math.pow((1+(perc/100)), time);
finAmount = princ*power;
curValue = NumberFormat.getCurrencyInstance().format(finAmount);
add(display);
display.setText("Computed Compound Interest is: ");
add(displayVal);
displayVal.setText("" + curValue);
}
});
}
}
Edited by Roger, 19 October 2011 - 03:59 PM.
added [code] tags


Sign In
Create Account

Back to top









