I'm sure this is simple - but I cannot seem to resolve it, or find the right answer. I have a jave applet project to calculate a car loan. I have it done and it is working EXCEPT....
Each calculation is correct and displays if I comment out the other 2.
When I leave all 3 - just the last output shows...
I need all 3 output lines to show on my project... I've tried some different append syntax - but not finding the right ones...get nothing but errors.
I'd sure appreciate any recommendations ...thanks in advance!
Here's my code:
import java.awt.event.*; //import three
public class carLoanApplet2ND extends Applet implements ActionListener //action is ActionListener - extends means to expect
Label Title = new Label("Car Loan Calculator"); //title is the variable-name it anything
Label costCarLabel = new Label ("Please enter the Price of the Car:"); //this is a prompt label
TextField costCarField = new TextField(25); //this is a text box -25 characters
Label downPaymentLabel = new Label ("Please enter the down payment:"); //this is another prompt
TextField downPaymentField = new TextField(25); //text field to get data
Label loanPeriodLabel = new Label ("Please enter the Loan Period in Years:"); //this is another prompt
TextField loanPeriodField = new TextField(25); //text field to get data
Button calcButton = new Button("Calculate Car Payment"); //button name label is in " "
Label outputLabel = new Label ("Enter the data and then click the button");
public void init()
// Set Background color to cyan
add(Title); // display title
add(costCarLabel); //display label
calcButton.addActionListener(this); //add button that states action performed - calls method
public void actionPerformed(ActionEvent e) //this is calculation method
double costCar, downPayment, loanPeriod, loan, interest, payment; //pass values
//Converting input to values
costCar =(double)Integer.parseInt(costCarField.getText()); //convert to value
downPayment = (double)Integer.parseInt(downPaymentField.getText());
loanPeriod = (double)Integer.parseInt(loanPeriodField.getText());
//Calculation amount of loan
loan = costCar - downPayment;
if (loan < 5000)
interest = .089;
if (loan < 7500)
interest = .079;
if (loan < 8500)
interest = .069;
if (loan < 10000)
interest = .059;
interest = .039;
payment = ((loan*interest) + loan) / (loanPeriod*12);
//Output loan amount
outputLabel.setText ("The Loan Amount = $" + loan);
outputLabel.setText ("The Interest Rate is = " + interest);
outputLabel.setText ("The Loan Payment is = $" + Math.round(payment));