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

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

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

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

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

  • In Java Create a testing class that does the following to the given codes below: To...

    In Java Create a testing class that does the following to the given codes below: To demonstrate polymorphism do the following: Create an arraylist to hold 4 base class objects Populate the arraylist with one object of each data type Code a loop that will process each element of the arraylist Call the first ‘common functionality’ method Call the second ‘common functionality’ method Call the third ‘common functionality’ method Verify that each of these method calls produces unique results Call...

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

  • Below are the Car class and Dealership class that I created In the previous lab import...

    Below are the Car class and Dealership class that I created In the previous lab import java.util.ArrayList; class Car { private String make; private String model; private int year; private double transmission; private int seats; private int maxSpeed; private int wheels; private String type; public Car() { } public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) { this.make = make; this.model = model; this.year = year; this.transmission = transmission; this.seats =...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

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