的這裏的主類構造子
**
** Assignment class
**
** This class represents an Assignment.
**
****************************************************/
public class Assignment {
private String name;
private double pointsPossible;
private double pointsEarned;
// Assignment constructor
//
// postcondition: all instance variables are initialized with
// the given values.
public Assignment (String n, double ptsPoss, double ptsEarned) {
name =n;
pointsPossible=ptsPoss;
pointsEarned=ptsEarned;
}
// getName accessor method
//
// postcondition: returns the name of this Assignment public
String getName() {
return name;
}
// getPointsPossible accessor method
//
// postcondition: returns the points possible for this Assignment
public double getPointsPossible() {
return pointsPossible;
}
// getPointsEarned accessor method
//
// postcondition: returns the points earned for this Assignment
public double getPointsEarned() {
return pointsEarned;
}
}
,當我嘗試使用我的訪問者在我的子類,我得到一個錯誤試圖初始化它的變量
這裏的子類
import java.util.ArrayList;
/****************************************************
**
** CategoryAssignment class
**
** This class represents an CategoryAssignment.
** Do not add any additional methods to this class.
**
****************************************************/
public class CategoryAssignment extends Assignment {
// declare any new instance variables that you need here
// don't forget to make them private!
// don't declare more that you really need!
// CategoryAssignment constructor
//
// postcondition: all instance variables are initialized with
// the given values.
public CategoryAssignment (String n, double ptsPoss, double ptsEarned, String cat) {
}
// getCategoryName accessor method
//
// postcondition: returns the name of the category associated
// with this CategoryAssignment
public String getCategoryName() {
return cat;
}
}
我無法獲得子類的變量初始化。還有,這是一個成績冊項目,將類別變量存儲在數組或ArrayList中會很明智嗎?
什麼錯誤?請顯示堆棧跟蹤。此外,請正確格式化代碼 – ItamarG3
我從不在類中定義'cat'。 – Compass