主要方法 DriverMortgageClass.java
Main method DriverMortgageClass.java
我即将完成此程序,但无法 运行,因为它需要一个 main 方法。但是,每当我输入它时,我都会收到错误代码 illegal start of expression。有人可以指出此代码片段中主要方法所属的位置吗?下面是我写的代码。我还被指示使用 Javadoc 实用工具,但我仍然不确定它是什么以及如何使用它。我相信我使用 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
}
it needs a main method
然后添加一个main方法和JavaDoc
/**
* This is a JavaDoc. Describe the class here.
*
**/
public class DriverMortgageClass
{
// Other code...
public static void main(String[] args) {
new DriverMortgageClass().start();
}
}
我即将完成此程序,但无法 运行,因为它需要一个 main 方法。但是,每当我输入它时,我都会收到错误代码 illegal start of expression。有人可以指出此代码片段中主要方法所属的位置吗?下面是我写的代码。我还被指示使用 Javadoc 实用工具,但我仍然不确定它是什么以及如何使用它。我相信我使用 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
}
it needs a main method
然后添加一个main方法和JavaDoc
/**
* This is a JavaDoc. Describe the class here.
*
**/
public class DriverMortgageClass
{
// Other code...
public static void main(String[] args) {
new DriverMortgageClass().start();
}
}