Search code examples
javamain-method

Main method DriverMortgageClass.java


I am close to completing this program but it cannot run because it needs a main method. However whenever I enter it I recieve the error code illegal start of expression. Can someone point out where the main method belongs in this code snippet? Bellow is the code I have written. I have also been instructed to use the Javadoc utility tool and am still unsure of what that is and how to use it. I believe I am on the right track by using java.util.doc

import javax.swing.*;
import java.text.*;
import java.util.*;

public class DriverMortgageClass
{


   public double annualInterestRate;
   public int numberOfYears;
   public double loanAmount;
   public double monthlyPayment;
   public double totalPayment;

  
   //set decimal format
   DecimalFormat df= new DecimalFormat ("0.00");
   
   private Mortgage mortgage;
   
   public DriverMortgageClass()
   {
   
   mortgage = new Mortgage();
   }

public void start()
{
  
//get input for interest rate
String annualInterestRateString = JOptionPane.showInputDialog(null,"Enter yearly interest rate, for example 8.25",JOptionPane.QUESTION_MESSAGE);
annualInterestRate=Double.parseDouble(annualInterestRateString);
mortgage.setAnnualInterestRate(annualInterestRate);

//get input for number of years
String numberOfYearsString = JOptionPane.showInputDialog(null,"Enter number of years as an integer, for example 5",JOptionPane.QUESTION_MESSAGE);
numberOfYears= Integer.parseInt(numberOfYearsString);
mortgage.setNumberOfYears(numberOfYears);

//set loan amount
String loanAmountString = JOptionPane.showInputDialog(null,"Enter loan amount, for example 120000.95",JOptionPane.QUESTION_MESSAGE);
loanAmount= Integer.parseInt(loanAmountString);
mortgage.setLoanAmount(loanAmount);


//calculate the monthly and total payment
monthlyPayment=loanAmount*annualInterestRate /(1-(Math.pow(1/(1+annualInterestRate),numberOfYears*12)));
totalPayment=monthlyPayment*numberOfYears*12;

//display monthly and total payment
JOptionPane.showMessageDialog(null,"The monthly payment is"+monthlyPayment 
+"The total payment is"+totalPayment);
       

System.exit(0);
}// end main method
}


Solution

  • it needs a main method

    Then add a main method and JavaDoc

    /**
    *  This is a JavaDoc. Describe the class here. 
    *
    **/
    public class DriverMortgageClass
    {
    
    
        // Other code...
    
        public static void main(String[] args) {
            new DriverMortgageClass().start();
        } 
    }