问题来了:
<块引用>设计一个名为 Staff 的超类,详细信息为 StaffId、Name、Phone、Salary。通过编写三个子类来扩展该类,即教学(领域、出版物)、技术(技能)和合同(期间)。写一个 Java 读取和显示所有三个类别的至少 3 个工作人员对象的程序。
class staff
{
<p>private int StaffId;
private String Name;
private String Phone;
private long Salary;
public staff(int staffId ,String name,String phone,long salary)
{
StaffId = staffId;
Name = name;//This keyword??
Phone = phone;
Salary = salary;
}
public void Display()
{
System.out.print("\t"+StaffId+"\t"+Name+"\t"+Phone+"\t"+Salary);
}
}
class Teaching extends staff
{
private String Domain;
private int Publications;
public Teaching(int staffId,String name,String phone,long salary,String domain,int publications)
{
super(staffId,name,phone,salary);//Calls the parent class directly
Domain = domain;
Publications = publications;
}
public void Display()
{
super.Display();//Call super class method
System.out.print("\t"+Domain+"\t"+Publications+"\t\t"+"--"+"\t"+"--"); //System.out.println(" "+n);
}
}
class Technical extends staff
{
private String Skills;
public Technical(int staffId,String name,String phone,long salary,String skills)
{
super(staffId,name,phone,salary);
Skills = skills;
}
public void Display()
{
super.Display();
System.out.print("\t"+"--"+"\t"+"--"+"\t\t"+Skills+"\t"+"--");
}
}
class Contract extends staff
{
private int Period;
public Contract(int staffId,String name,String phone,long salary,int period)
{
super(staffId,name,phone,salary);
this.Period = period;
}
public void Display()
{
super.Display();
System.out.print("\t"+"--"+"\t"+"--"+"\t\t"+"--"+"\t"+Period);
}
}
public class staffdetail<br> {
public static void main(String args[])
{
int StaffId;
String Name,Phone;
long Salary;
String Domain;
int Publications;
String Skills;
int Period,i,n;
Scanner sc = new Scanner(System.in);
staff stuff[] = new staff[50];
System.out.println("Enter the no of teaching staff\n ");
n = sc.nextInt();
sc.nextLine();
for( i=1;i<n;i++)//skipped
{
System.out.println("Enter the teaching staff details:StaffIf,Name,Phone,Salary,Domain,Publications ");
Name = sc.nextLine();<br>
Phone = sc.nextLine();
Domain=sc.nextLine();
StaffId = sc.nextInt();
Publications = sc.nextInt();
Salary = sc.nextLong();
stuff[i]=new Teaching(StaffId,Name,Phone,Salary,Domain,Publications);
}
System.out.println("Enter number of teaching staff:");
int m = sc.nextInt();
for(i=n+1;i<=(m+n);i++)
{
System.out.println("Enter" +i+"Technical staff details:staffid,name,phone,salary,skills");
StaffId = sc.nextInt();
Name = sc.next();
Phone = sc.next();
Salary = sc.nextLong();
Skills= sc.next();
stuff[i]=new Technical(StaffId,Name,Phone,Salary,Skills)
}//no response after exectuting this
System.out.println("Enter the number of staff");
int p = sc.nextInt();
for( i=n+m+1;i<=m+n+p;i++)
{
System.out.println("Enter"+i+"Contract staff details:Staffid,Name,Phone,Salary,Period");
StaffId = sc.nextInt();
Phone = sc.nextLine();
Salary = sc.nextInt();
Period = sc.nextInt();
Name = sc.next();
stuff[i]= new Contract(StaffId,Name,Phone,Salary,Period);
}
System.out.println("\"Staff ID \tName \t Phone \t Salary \t Domain \t Publications \t Skills \t Period");
for( i=1;i<n+m+p;i++)
{
stuff[i].Display();
System.out.println();
}
}
----------
}