Question

In this Assignment, you will create a Student class and a Faculty class, and assign them as subclasses of the superclass UHPe
Details This is the first time that you have seen UML as your instructions for building code. The UML diagram tells you every
• faculty List is an ArrayList holding all of the Faculty objects. Every time a Faculty is created, it should be added to thi
getStudent(int) should return a Student object that matches the id specified by the integer argument when called in the Stude
public class People Program public static void main(String) args) { //Build the tvo data sets buildstudentData) baldFacultyat
Last picture is the tester program!
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
import java.io.*;
import java.lang.*;

class UHPerson
{
String name;
int id;
  
void setName(String name)
{this.name = name;}
String getName()
{return this.name;}
  
void setID(int id)
{this.id = id;}
int getID()
{return this.id;}
  
@Override
public String toString()
{ return (this.id+" "+this.name); }
}

class Student extends UHPerson
{
static ArrayList<Student> studentList = new ArrayList<>();
String level;
ArrayList<String> courseList = new ArrayList<>();
  
Student(String name, int id, String level)
{
this.name = name;
this.id = id;
this.level = level;
}
  
static Student getStudent(int id)
{
Student res = null;
for(Student st:studentList)
if(st.id == id) {res = st;break;}
  
return res;
}
  
static ArrayList<Student> getRoster()
{
return studentList;
}
  
void addCourses(String course)
{
courseList.add(course);
}
  
ArrayList<String> getCourses()
{
return this.courseList;
}
  
String getLevel()
{
return this.level;
}
  
}


class Faculty extends UHPerson
{
static ArrayList<Faculty> facultyList = new ArrayList<>();
String rank;
String officeHours;
  
Faculty(String name, int id, String rank)
{
this.name = name;
this.id = id;
this.rank = rank;
}
  
static Faculty getFaculty(int id)
{
Faculty res = null;
for(Faculty fac:facultyList)
if(fac.id == id) {res = fac; break;}
  
return res;
}
  
static ArrayList<Faculty> getRoster()
{ return facultyList; }
  
void setOfficeHours(String officeHours)
{ this.officeHours = officeHours;}

String getOfficeHours()
{
return this.officeHours;
}
  
String getRank()
{ return this.rank;}
}

class UHPeopleProgram
{
public static void buildStudentData()
{
Student st;
st = new Student("Alice", 12345, "Freshman");
st.addCourses("ICS111");
st.addCourses("ICS141");
  
Student.studentList.add(st);
st = new Student("Bob", 23456, "Sophomore");
st.addCourses("ICS111");
st.addCourses("ICS141");
st.addCourses("ICS211");
st.addCourses("ICS212");
st.addCourses("ICS241");
Student.studentList.add(st);
  
st = new Student("Carol", 34567, "Junior");
st.addCourses("ICS111");
st.addCourses("ICS141");
st.addCourses("ICS211");
st.addCourses("ICS212");
st.addCourses("ICS241");
st.addCourses("ICS314");
st.addCourses("ICS355");
st.addCourses("ICS414");
Student.studentList.add(st);
  
st = new Student("Diane", 45678, "Senior");
st.addCourses("ICS111");
st.addCourses("ICS141");
st.addCourses("ICS211");
st.addCourses("ICS212");
st.addCourses("ICS241");
st.addCourses("ICS314");
st.addCourses("ICS355");
st.addCourses("ICS414");
st.addCourses("ICS464");
st.addCourses("ICS499");
Student.studentList.add(st);
  
st = new Student("Elmo", 56789, "Freshman");
st.addCourses("ICS111");
st.addCourses("ICS141");
st.addCourses("ICS211");
Student.studentList.add(st);
}
  
public static void buildFacultyData()
{
Faculty fac;
  
fac = new Faculty("Dr. Angry", 54321, "Full Professor");
fac.setOfficeHours("MW 1-3");
Faculty.facultyList.add(fac);
  
fac = new Faculty("Dr. Boring", 65432, "Full Professor");
fac.setOfficeHours("TuTh 9-11");
Faculty.facultyList.add(fac);
  
fac = new Faculty("Dr. Candy", 76543, "Associate Professor");
fac.setOfficeHours("M 8-12");
Faculty.facultyList.add(fac);
  
fac = new Faculty("Dr. Dreary", 87654, "Associate Professor");
fac.setOfficeHours("MWF 11-2");
Faculty.facultyList.add(fac);
  
fac = new Faculty("Dr. Excitment", 98765, "Assistant Professor");
fac.setOfficeHours("TuTh 2-5");
Faculty.facultyList.add(fac);
}
  
public static void main(String args[])
{
int idNum;
  
/*build two data set*/
buildStudentData();
buildFacultyData();
  
/*Test methods for student data*/
System.out.println(Student.getRoster());
  
for(Student s:Student.getRoster())
{
idNum = s.getID();
s = Student.getStudent(idNum);
System.out.print(s + ", ");
System.out.print(s.getLevel() + ", ");
System.out.println(s.getCourses());
}
System.out.println();
  
/*Test methods for faculty data*/
System.out.println(Faculty.getRoster());
  
for(Faculty fac:Faculty.getRoster())
{
idNum = fac.getID();
fac = Faculty.getFaculty(idNum);
System.out.print(fac + ", ");
System.out.print(fac.getRank() + ", ");
System.out.println(fac.getOfficeHours());
}
}
  
  
}


Add a comment
Know the answer?
Add Answer to:
Last picture is the tester program! In this Assignment, you will create a Student class and...
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 help: 1.1) Create a class TA  that extends class Student. 1.2) Add a variable to the...

    Java help: 1.1) Create a class TA  that extends class Student. 1.2) Add a variable to the TA class to represent the course the student is TA'ing. 1.3) Provide a constructor for the class so the code in the PeopleFactory will work as provided. 1.4) Provide a toString() method for the TA  class so that TA's will output as shown in the sample code. Provide a class Staff so that you can un-comment the lines of code in the PeopleFactory class that...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

  • 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...

  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

  • Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person...

    Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...

  • I have a little problem about my code. when i'm working on "toString method" in "Course"...

    I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student {    private String firstName;    private String lastName;    private String id;    private boolean tuitionPaid;       public Student(String firstName, String lastName, String id, boolean tuitionPaid)    {        this.firstName=firstName;        this.lastName=lastName;        this.id=id;        this.tuitionPaid=tuitionPaid;    }   ...

  • 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...

  • I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String...

    I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String name, major, status; private int rank;    public Student() { this.name = this.major = this.status = ""; this.rank = 0; }    public Student(String name, String major, String status) { this.name = name; this.major = major; this.status = status; } public String getName() { return name; } public String getMajor() { return major; } public String getStatus() { return status; }    public int...

  • Please provide the code for the last part(client side program). yes i have all the class...

    Please provide the code for the last part(client side program). yes i have all the class implementations. ``` person.h #ifndef PERSON_H #define PERSON_H #include <string> using namespace std; class person { public: person(); string getname() const; string getadd() const; string getemail() const; string getphno() const; string toString() const; private: string name; string add; string email; string phno; }; ```person.cpp #include "person.h" person::person() { name = "XYZ"; add="IIT "; email="%%%%"; phno="!!!!!"; } string person::getname() const { return name; } string person::getadd()...

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