Answer to Question #279122 in Java | JSP | JSF for htp

Question #279122

Recall the following scenario discussed during the class. Develop a code base to represent the scenario. Add a test class to invoke Lecturer and Student class by creating atleast one object from each.

Note: All the common attributes and behavior stored in the super class and only the specific fields and behavior stored in subclasses.

Student

-         name

-         id

-         course

      +    setName()/getName()

       +   setID()/getID()

     +     setCourse()/getCourse()

Lecturer

-         name

-         id

-         programme

      +    setName()/getName()

     +     setID()/getID()

     +     setProg()/getProg()

Person

Identify field and attributes to be stored in this class



1
Expert's answer
2021-12-13T16:57:40-0500


package persons;




public class Persons {


 private String  name;
private int        id;


  void setName(String n){
      name = n;
  }
    String getName(){
        return name;
    }


       void setID(int i){
           id = i;
       }
               
        int getID(){
            return id;
        }
    public static void main(String[] args) {
       Student st = new Student();
       st.setDetails("John", 23, "Computer Science");
       st.display();
       
       Lecturer lec = new Lecturer();
       lec.setData("Abraham", 343, "Economics");
       lec.display();
    }
    
}


class Student extends Persons{
    private String course;
    void setDetails(String n, int i, String c){
        setName(n);
        setID(i);
        course = c;
    }
    
    void display(){
        System.out.printf("Student Name:"
                + " %s\nStudent ID: %d\nStudent Course: %s",getName(), getID(), course);
    }
}
class Lecturer extends Persons{
    private String programme;
    void setData(String n, int i, String p){
        setName(n);
        setID(i);
        programme = p;
    }
     void display(){
        System.out.printf("Lecturer Name: "
                + "%s\nLecturer ID: %d\nLecturer"
                + " programme: %s",getName(), getID(), programme);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog