Question

Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman...

Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method in each class to display the class name and the person's name. Write an application to create objects of type Student and Staff, put them in a SINGLE ArrayLlist, then loop through the ArrayList and print the person's name and the class name of the objects.

1 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Person.java:


public abstract class Person {
   private String name;
   private String address;
   private String phoneNo;
   private String emailID;
   public Person(String name, String address, String phoneNo, String emailID) {
       this.name = name;
       this.address = address;
       this.phoneNo = phoneNo;
       this.emailID = emailID;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public String getAddress() {
       return address;
   }
   public void setAddress(String address) {
       this.address = address;
   }
   public String getPhoneNo() {
       return phoneNo;
   }
   public void setPhoneNo(String phoneNo) {
       this.phoneNo = phoneNo;
   }
   public String getEmailID() {
       return emailID;
   }
   public void setEmailID(String emailID) {
       this.emailID = emailID;
   }
   @Override
   public String toString() {
       return " " + name + " " + getClass();
   }

}

Student.java:


public class Student extends Person{

   public Student(String name, String address, String phoneNo, String emailID) {
       super(name, address, phoneNo, emailID);
       // TODO Auto-generated constructor stub
   }
   enum CreditHourStatus
{
       freshman, sophomore, junior, senior;
}
   @Override
   public String toString() {
   return " " + getName() + " " + getClass();
   }
  
}

Staff.java:

import java.util.Date;

public class Staff extends Person{
  
   private String office;
   private int salary;
   private Date dateHired;
   public Staff(String name, String address, String phoneNo, String emailID) {
       super(name, address, phoneNo, emailID);
       // TODO Auto-generated constructor stub
   }
   public String getOffice() {
       return office;
   }
   public void setOffice(String office) {
       this.office = office;
   }
   public int getSalary() {
       return salary;
   }
   public void setSalary(int salary) {
       this.salary = salary;
   }
   public Date getDateHired() {
       return dateHired;
   }
   public void setDateHired(Date dateHired) {
       this.dateHired = dateHired;
   }
   @Override
   public String toString() {
       return " " + getName() + " " + getClass();
}
  
  

  

}

PersonTest.java:

import java.util.ArrayList;

public class PersonTest {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Student s=new Student("Ram", "us", "9000100100", "[email protected]");
       Staff s1=new Staff("Rah","ff","932523942","[email protected]");
       ArrayList<Person> arr=new ArrayList<Person>();
       arr.add(s);
       arr.add(s1);
       for (Person i : arr){
           System.out.println(i.toString());
       }
   }

}

output:

Add a comment
Answer #2
Nasra Fresh man shoe phore
source: Java
answered by: Nasra
Add a comment
Know the answer?
Add Answer to:
Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Programming Design a class named Person and its two subclasses named Student and Employee. A...

    Java Programming Design a class named Person and its two subclasses named Student and Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, date hired. Define a class named MyDate that contains the fields year, month, and day. Override the toString method in each class to display the class name and the person's name....

  • a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person...

    a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate classto create an object for date hired. A faculty...

  • Design a class named Person and its two derived classes named Student and Employee. MakeFaculty and Staff derived classes of Employee

    In Java(The Person, Student, Employee, Faculty, and Staff classes)Design a class named Person and its two derived classes named Student and Employee. MakeFaculty and Staff derived classes of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). An employee has an office, salary, and date hired. Define a class namedMyDate that contains the fields year, month, and day. A faculty member has office hours and a rank....

  • Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person...

    Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...

  • Part I: (The Myate class) Design a class named MyDate. The class contains: • The data...

    Part I: (The Myate class) Design a class named MyDate. The class contains: • The data fields year, month, and day that represent a date. Month is 0-based, i.e., 0 is for January. • A no-arg constructor that creates a MyDate object for the current date. • A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. • A constructor hat constructs a MyDate object with the specified year, month, and...

  • 1. Design and implement classes. Design a class named Account and its two subclasses named Checking and Saving. Make Flexible and NotFlexbile subclasses of Saving. An account has a name, address, phon...

    1. Design and implement classes. Design a class named Account and its two subclasses named Checking and Saving. Make Flexible and NotFlexbile subclasses of Saving. An account has a name, address, phone number, and balance. A checking account has a overdraft limit. A saving account has an interest rate. A flexible saving account has the accumulated interest rate. A none flexible account has the expected accumulated interest rate at the maturity of the account. Override the toString method in each...

  • For task 2, implement the three classes (Person, Student, and Staff) that are described above. Note...

    For task 2, implement the three classes (Person, Student, and Staff) that are described above. Note that classes Staff and Student are derived from the superclass Person -- in other words Staff and Student inherit from Person. Make sure that the subclasses Student and Staff invoke the superclass' constructors and correctly inherit the variables and methods from the superclass Person. Also note that Person is an abstract class. <abstract> Person -name:String -address:String = “String” +getName():String +getAddress():String +setAddress(address:String):void +setName(name:String):void Staff -school:String...

  • Please answer all the questions 2. Design two programs named BaseClass and SubClass. In BaseClass, define...

    Please answer all the questions 2. Design two programs named BaseClass and SubClass. In BaseClass, define a variable xVar (type: char, value: 65), and a method myPrint to print xVar. SubClass is a subclass of BaseClass. In SubClass, define a variable yVar (type: int, value: 16) and another variable strVar (type: String, value: "java program!"). There is also a method myPrint to print the value of yVar and strVar in SubClass, as well as an additional method printAll, in which...

  • PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class...

    PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class has 4 attributes: (1) student ID: protected, an integer of 10 digits (2) student name: protected (3) student group code: protected, an integer (1 for undergraduates, 2 for graduate students) (4) student major: protected (e.g.: Business, Computer Sciences, Engineering) Class Student declaration provides a default constructor, get-methods and set-methods for the attributes, a public abstract method (displayStudentData()). PART II: Create a Java class named...

  • Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...

    Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT