这个代码我做了他们我不知道这是否正确。
Person.Java
public class Person {
private String fname;
private String lname;
public Person(){
this.fname="";
this.lname="";
}
public Person(String fname,String lname){
this.fname = fname;
this.lname = lname;
}
public void setfirstname(String fname){
this.fname = fname;
}
public void setlastname(String lname)
{
this.lname = lname;
}
public String getfirstname(){
return fname;
}
public String getlastname(){
return lname;
}
}
Student.java
public class Student extends Person{
private String studentid;
private String studenttype;
public Student(){
this.studentid = "";
this.studenttype = "";
}
public Student(String studentid,String studenttype)
{
this.studentid = studentid;
this.studenttype = studenttype;
}
public void setStudentId(String studentid)
{
this.studentid = studentid;
}
public void setStudentType(String studenttype){
this.studenttype = studenttype;
}
public String getStudentID(){
return studentid;
}
public String getStudentType()
{
return studenttype;
}
}
Course.java
的 Course.java
我想我现在还没完成,我对这个问题有一些问题,你可以帮我列一下这个代码
public class Course extends Student{
private String courseid;
private String coursedesc;
private Subject subject[];
public Course()
{
this.courseid = "";
this.coursedesc = "";
}
public Course(String courseid,String coursedesc)
{
this.courseid = courseid;
this.coursedesc = coursedesc;
}
public void setCourseId(String courseid)
{
this.courseid = courseid;
}
public void setCourseDesc(String coursedesc)
{
this.coursedesc = coursedesc;
}
public String getCourseId()
{
return courseid;
}
public String getCourseDesc()
{
return coursedesc;
}
public void addSubject(Subject subject)
{
}
}
Subject.java
你能帮帮我吗? **
答案 0 :(得分:0)
你的错误是什么?
public String getStudentType()
{
return this.studenttype;
}
请务必返回this.studenttype并为每个getter执行此操作
答案 1 :(得分:-1)
使用ArrayList<Subject>
代替Subject[]
。
像那样:
public class Course extends Student {
private String courseid;
private String coursedesc;
private List<Subject> subjects;
public Course()
{
this.courseid = "";
this.coursedesc = "";
subjects = new ArrayList<Subject>();
}
public Course(String courseid, String coursedesc)
{
this();
this.courseid = courseid;
this.coursedesc = coursedesc;
}
public void setCourseId(String courseid)
{
this.courseid = courseid;
}
public void setCourseDesc(String coursedesc)
{
this.coursedesc = coursedesc;
}
public String getCourseId()
{
return courseid;
}
public String getCourseDesc()
{
return coursedesc;
}
public void addSubject(Subject subject)
{
subjects.add(subject);
}
public List<Subject> getSubjects()
{
return subjects;
}
}