{
String name; / / Name
String ID; / / Student ID
String birth; / / Date of Birth
String zhuanye ;/ / Professional
/ * defines two constructors , used for object initialization * /
Student () / / Constructor 1: No reference
{
}
Student (String n, String id, String b, String z) / / Constructor 2: Participation
{
/ * initial value * /
name = n;
ID = id;
birth = b;
zhuanye = z;
}
/ * define the member method for external access to the property * /
public void setname (String n) / / Set the name
{
name = n;
}
public String getname () / / Get the name
{
return name;
}
public void setID (String id) / / Set Student ID
{
ID = id;
}
public String getID () / / Gets Student ID
{
return ID;
}
public void setbirth (String b) / / Set Date of Birth
{
birth = b;
}
public String getbirth () / / Gets Date of Birth
{
return birth;
}
public void setzhuanye (String z) / / set Professional
{
zhuanye = z;
}
public String getzhuanye () / / obtain professional
{
return zhuanye;
}
public void ShowInfo () / / Show all data
{
System.out.println (" Student Name :" + getname () + "" + " Student ID: "+ getID () +" "+" Date of Birth : "+ getbirth () +" "+" professional : "+ getzhuanye ());
}
}
class Teacher / / define a class teacher
{
/ * define a class of six member variables : name, job number, title, department , course hours per week * /
String name;
String ID;
String zhicheng;
String bumen;
String subject;
int time;
/ * defines two constructors , used for object initialization * /
Teacher () / / Constructor 1: No reference
{
}
Teacher (String na, String id1, String z, String b1, String s, int t) / / Constructor 2: Participation
{
/ * initial value * /
name = na;
ID = id1;
zhicheng = z;
bumen = b1;
subject = s;
time = t;
}
/ * define the member method for external access to the property * /
public void setname (String na) / / Set the name
{
name = na;
}
public String getname () / / Get the name
{
return name;
}
public void setID (String id1) / / set the job number
{
ID = id1;
}
public String getID () / / get job number
{
return ID;
}
public void setzhicheng (String z) / / Set title
{
zhicheng = z;
}
public String getzhicheng () / / Get title
{
return zhicheng;
}
public void setbumen (String b1) / / set up departments
{
bumen = b1;
}
public String getbumen () / / get the department
{
return bumen;
}
public void setsubject (String s) / / Set Course
{
subject = s;
}
public String getsubject () / / access courses
{
return subject;
}
public void settime (int t) / / set the class
{
time = t;
}
public int gettime () / / Get lesson
{
return time;
}
public void ShowInfo () / / Show all data
{
System.out.println (" Name of Teacher :" + getname () + "" + " job number : " + getID () + "" + " title :" + getzhicheng () + "" + " department :" + getbumen () + "" + " course : "+ getsubject () +" "+" class : "+ gettime ());
}
}
class A1 extends Student / / define a TA class A1, inherits the Student class ( a class can not inherit from multiple parent classes ! ! ! )
{
Teacher t;
A1 () / / constructor argument 1: No reference
{
}
A1 (String newname, String newID, String newbirth, String newzhuanye, Teacher newteacher) / / constructor parameter 2: Participation
{
super (newname, newID, newbirth, newzhuanye) ;/ / subclass can call the parent class constructor declaration
t = newteacher;
}
public void setname (String newname) / / Set the name
{
name = newname;
}
public String getname () / / Get the name
{
return name;
}
public void setID (String newID) / / Set Student ID
{
ID = newID;
}
public String getID () / / Gets Student ID
{
return ID;
}
public void setbirth (String newbirth) / / Set Date of Birth
{
birth = newbirth;
}
public String getbirth () / / Gets Date of Birth
{
return birth;
}
public void setzhuanye (String newzhuanye) / / set Professional
{
zhuanye = newzhuanye;
}
public String getzhuanye () / / obtain professional
{
return zhuanye;
}
public void ShowInfo () / / Show all data
{
System.out.println (" TA Name :" + super.getname () + "" + " Student ID: " + super.getID () + "" + " Date of Birth :" + super.getbirth () + "" + " professional :" + super.getzhuanye () + " "+ " course : "+ t.getsubject () +" "+" class : "+ t.gettime ());
}
}
public class xqq_Applicationtigao201
{
public static void main (String args []) / / define the main method , as the program is running the main entrance
{
Teacher t1 = new Teacher (" Joe Smith ", " 001", " professor ", "Network Engineering " "java", 4);
Student s1 = new Student (" Lee ", " 2012122666 ", " 19940103 ", "Network Project" ) ;
A1 a = new A1 (" Lee ", " 2012122666 ", " 19940103 ", " network engineering ", " teacher ");
t1.ShowInfo ();
s1.ShowInfo ();
a.ShowInfo ();
}
}
error message is:
C: \ Users \ xuqianqian \ Desktop \ xqq_Applicationtigao201.java: 188: can not find symbol
Symbol: Constructor A1 (java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
Location: Class A1
A1 a = new A1 (" Lee ", " 2012122666 ", " 19940103 ", " network engineering ", " teacher ");
^
1 error
tools to complete the exit code 1
should be how to modify ~ ~ ! ! ! Extremely grateful ~
------ Solution ------------------------------------- -------
public class xqq_Applicationtigao201 {
public static void main(String args[])// 定义main方法,作为程序运行主入口
{
Teacher t1 = new Teacher("张三", "001", "教授", "网络工程系", "java", 4);
Student s1 = new Student("李一", "2012122666", "19940103", "网络工程");
A1 a = new A1("李一", "2012122666", "19940103", "网络工程", "teacher");
t1.ShowInfo();
s1.ShowInfo();
a.ShowInfo();
}
}
把上面这个里面的
A1 a = new A1("李一", "2012122666", "19940103", "网络工程", "teacher");
改成
A1 a = new A1("李一", "2012122666", "19940103", "网络工程", t1);
就可以了
另外建议:
别A1. A2这么命名
------ For reference only ------------------------- --------------
A1 a = new A1 (" Lee ", " 2012122666 ", " 19940103 ", " network engineering ", " ; teacher ");
This constructor parameter in question , the last parameter to be passed Teacher instance of the class , not a string type.
to A1 a = new A1 (" Lee ", " 2012122666 ", " 19940103 ", " network engineering ", new Teacher ()); it
没有评论:
发表评论