我不確定enum系列是否處於正確的位置,但是我在主類內部或外部得到相同的錯誤。這些枚舉; WILMA,FRED,BETTY,& BARNEY將提供 數據來計算他們的退休儲蓄。Java中的枚舉構造函數的問題
public class Assignment5
{
enum Family
{
WILMA("Wilma", "Flintstone", 5000, 0.05, 10, 35),
FRED("Fred", "Flintstone", 15000, 0.075, 7, 30), //fred might swap with betty
BETTY("Betty", "Rubble", 7500, 0.0375, 10, 25),
BARNEY("Barney", "Rubble", 5000, 0.09, 10, 35),
}
//The properties’ 「getters」/accessors should go here.
//instance fields
private final String firstName; //first names
private final String lastName; //last names
private final int annualDeposit; //annual deposit
private final double annualRate; //annual rate
private final int yearsDeposit; //number of years depositing
private final int yearsCalc; //number of years to compound
//enum family constructor
Assignment5(String firstName, String lastName, int annualDeposit, double annualRate, int yearsDeposit, int yearsCalc)
{
this.firstName = firstName;
this.lastName = lastName;
this.annualDeposit = annualDeposit;
this.annualRate = annualRate;
this.yearsDeposit = yearsDeposit;
this.yearsCalc = yearsCalc;
}
//getter for firstName
public String getFirstName()
{
return firstName;
}
//getter for lastName
public String getLastName()
{
return lastName;
}
//getter for annual deposit
public int getAnnualDeposit()
{
return annualDeposit;
}
//getter for annual rate
public double getAnnualRate()
{
return annualRate;
}
//getter for years deposit
public int getYearsDeposit()
{
return yearsDeposit;
}
//getter for years calc
public int getYearsCalc()
{
return yearsCalc;
}
//main method
//formulas for calculating retirement account and printing results will go here
public static void main(String[] args)
{
}
}
什麼是'Assignment5'?難道不是「家庭」嗎? – Arkadiy 2014-10-28 18:18:55
這樣做會給我一個無效的方法聲明,我以前試過。 Assignment5是我的主類 – greaterbeing 2014-10-28 18:21:43
的名稱請參閱[本教程](http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html),特別向下滾動到「Planet」示例。基本上,你在enum'花括號之外的東西需要放在裏面。 – ajb 2014-10-28 18:25:10