0

So this is the question:

Design a superclass called Staff with details as StaffId, Name, Phone, Salary. Extend this class by writing three subclasses namely Teaching (domain, publications), Technical (skills), and Contract (period). Write a Java program to read and display at least 3 staff objects of all three categories.

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();
    }
}


----------


}
user207421
  • 289,834
  • 37
  • 266
  • 440

0 Answers0