Space for google add

Define an abstract class “Staff” and two sub-classes of this class – “FullTimeStaff” and “PartTimeStaff” .

  


Define an abstract class “Staff” with members name and address. Define two sub-classes of this class – “FullTimeStaff” (department, salary) and “PartTimeStaff” (number-of-hours, rate-perhour).
Define appropriate constructors. Create n objects which could be of either FullTimeStaff or PartTimeStaff class by asking the user’s choice. Display details of all “FullTimeStaff” objects and all “PartTimeStaff” objects.


ex3setb1.java 


import java.util.*;
import java.io.*;
abstract class Staff
{
Staff(String nm,String add)
{}
abstract void display();
}


class Fulltime extends Staff
{
Fulltime(String nm,String add,String dept,double sal)
{super(nm,add);}
void display(){}
}
class Parttime extends Staff
{
Parttime(String nm,String add,int n,int r)
{super(nm,add);}
}


class ex3setb1
{
main()
{
System.out.println("\nHow many objects");
int n=sc.nextInt();
Staff s[]=new Staff[n];
int flag[]=new int [n];
for(int i=0;i<n;i++)
{
System.out.println("\n1.Fulltime\n2.Parttime\n");
System.out.println("Enter choise");
int ch=sc.nextInt();
if(ch==1)
{   flag[i]=1;accept info;
s[i]=new Fulltime(x,y,z,w);
}
else
{    flag[i]=0;
s[i]=new Parttime(x,y,z,w);
}


}
for(int i=0;i<n;i++)
{
if(flag[i]==1)
{
System.out.println("Full time staff :");
s[i].display();
}
}
for(int i=0;i<n;i++)
{
if(flag[i]==0)
{
System.out.println("Part time staff :");
s[i].display();
}
}
}
}


Post a Comment

0 Comments