Announcement

Collapse
No announcement yet.

Need a hand with Java Format

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need a hand with Java Format

    Can anyone give me a hand with fixing the formatting on this? I can't get it to display right..it chops the first and last part of the sentance and doesnt display the answer in the correct place.

    Code:
    import java.text.*;//sets text format
    import java.awt.*;//sets user interface
    import java.awt.event.*;//provides interfaces and classes for events caused by java.awt
    import javax.swing.*;//provides compenents to work the same on all platorms
    import java.lang.Math;//provides abitily to do math
    import java.util.Locale;//sets location of currency
    
    public class Mortgage extends JApplet implements ActionListener
    {
    	JLabel Calculator = new
    	JLabel ("Scott's Mortgage Payment Calculator"); //labels name of program
    	JLabel CalculateLoan = new JLabel("This program will calculate your monthly mortgage payment based on loan terms of your choice."); // Tells user what program will be doing
    	JLabel UserOption = new JLabel("You will need to choose the loan amount, interest rate, and years of term."); //User directions for input
    	JLabel ClickButton = new JLabel("Click on the Calculate button to add input and see the resulting monthly payment amount."); //User Directions
    	JButton MonthlyPayment = new JButton("Calculate!"); //creates button to start user input
    	NumberFormat nformat = NumberFormat.getCurrencyInstance(Locale.US); //Sets Formatting of output to U.S. Dollars
    
    public void init()
    {
    	Container con = getContentPane();
    	con.setLayout(new FlowLayout());
    	con.add(Calculator);
    	con.add(CalculateLoan);
    	con.add(UserOption);
    	con.add(ClickButton);
    	con.add(MonthlyPayment);
    	MonthlyPayment.addActionListener(this);
    	//Container objects
    	}
    
    public void actionPerformed(ActionEvent e)
    {
    	Object source = e.getSource();
    	if (source == MonthlyPayment)
    	{
    		String LoanAmount = JOptionPane.showInputDialog(null, "Enter the amount of the loan:"); //accepts user input for amount of loan
    		String InterestRate = JOptionPane.showInputDialog(null, "Enter the annual interest rate:"); //user input for interest rate of the loan
    		String TermYears = JOptionPane.showInputDialog(null, "Enter the length of the term in years:"); //user input for length of loan
    		double amount = Double.parseDouble(LoanAmount); // sets percision of Loan amount
    		double interest = Double.parseDouble(InterestRate);// sets percision of Interest Rate
    		double rate = interest/100; //calucation of rate
    		double term = Double.parseDouble(TermYears);//Term of loan in years
    		double length = term*12;//Term of loan broken down to months
    		double payment; //sets percision of loan amount
    		payment = amount*(rate/12)/(1-1/Math.pow((1+rate/12), length));//Formula for solving for monthly payment for mortgage
    		CalculateLoan.setText("Your monthly payment will be " + nformat.format(payment)); //displays solved user input for mortgage payment
    		}
    	}
    }
    Why is it called tourist season, if we can't shoot at them?
Working...
X