-1
我即將完成此程序,但它無法運行,因爲它需要一個主要方法。然而,無論何時我輸入它,我都會收到錯誤代碼表達式的非法開始。有人可以指出這個代碼片段中主要方法的屬性嗎?貝婁是我寫的代碼。我也被指示使用Javadoc實用程序工具,但我仍然不確定它是什麼以及如何使用它。我相信,我在正確的軌道上,通過使用java.util.doc主要方法DriverMortgageClass.java
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
}
我也有另一個程序,與這封裝信息沒有包含在這個文件中。如果需要,我可以提供,但我真的需要知道的是在哪裏輸入我的主要方法的正確位置,以便我的程序能夠運行。 – David
主要方法必須具有簽名'public static void main(String [])''。你沒有這樣的方法。因此,你沒有一個主要的方法。 – bcsb1001