Question #62292

Create class Course as per its UML diagram. Then, create subclasses Faculty and Student that extend class Person from the Chapter 9 Assignment (just copy-paste it from our Chapter 9 assignment). Refer to the UML diagrams to give these classes attributes and methods. Do NOT add any attributes or methods that don't appear in the UML diagrams. Create an executable class named TestCollege to test your work. In TestCollege, add code that accomplishes the tasks below. The sample output might assist you to understand these tasks.
1

Expert's answer

2016-09-29T14:22:03-0400
public class Student extends Person(
private String status;
public Student() {
}
public Student(String name, String address, String phone, String email) {
super(name, address, phone, email);
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public void enrollCourse(Course course) {
course.addStudent(this);
}
@Override
public String toString() {
return super.toString() + "\n" + "Status: " + status + "\n";
}
}
public class Tester {
public static void main(String[] args) {
System.out.println(" == Testing Person class: == " + "\n");
Person person1 = new Person();
System.out.println(person1 + "\n");
Person person2 = new Person("James", "Some address", "Some phone", "Some email");
System.out.println(person2 + "\n");
System.out.println(" == Testing Student class: == " + "\n");
Student student1 = new Student();
System.out.println(student1);
Student student2 = new Student("James", "Some address", "Some phone", "Some email");
System.out.println(student2);
System.out.println(" == Testing Employee class: == " + "\n");
Employee employee1 = new Employee();
System.out.println(employee1 + "\n");
Employee employee2 = new Employee("James", "Some address", "Some phone", "Some email");
System.out.println(employee2 + "\n");
System.out.println(" == Testing Faculty class: == " + "\n");
Faculty faculty1 = new Faculty();
System.out.println(faculty1 + "\n");
Faculty faculty2 = new Faculty("James", "Some address", "Some phone", "Some email");
System.out.println(faculty2 + "\n");
System.out.println(" == Testing Course class == ");
System.out.println("Creating 3 students and enroll them to the Math course #107");
Course course = new Course("Math", 107);
student1 = new Student();
student2 = new Student();
Student student3 = new Student();
student1.enrollCourse(course);
student2.enrollCourse(course);
student3.enrollCourse(course);
System.out.println(course);
}
}
public class Course {
private String name;
private int id;
private ArrayList<Student> studentsEnrolled;
public Course() {
studentsEnrolled = new ArrayList<>();
}
public Course(String name, int id) {
this.name = name;
this.id = id;
studentsEnrolled = new ArrayList<>();
}
public String getName() {
return name;
}
public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public void setId(int id) {
this.id = id;
}
public void addStudent(Student student) {
studentsEnrolled.add(student);
}
@Override
public String toString() {
String str = "";
for (Student std: studentsEnrolled) {
str = str + std.toString() + "\n";
}
return "Course name: " + name + "\n" + "Course id: " + id + "\n" + "Students enrolled: " + "\n" + str;
}
}
public class Employee extends Person {
private String office;
private int salary;
private Date dateHired;
public Employee() {
}
public Employee(String name, String address, String phone, String email) {
super(name, address, phone, email);
}
public String getOffice() {
return office;
}
public int getSalary() {
return salary;
}
public Date getDateHired() {
return dateHired;
}
public void setOffice(String office) {
this.office = office;
}
public void setSalary(int salary) {
this.salary = salary;
}
public void setDateHired(Date dateHired) {
this.dateHired = dateHired;
}
@Override
public String toString() {
return super.toString() + "\n" + "Office: " + office + "\n" + "Salary: " + salary + "\n" + "Date hired: " + dateHired;
}
}
public class Faculty extends Person {
private String officeHour;
private String rank;
public Faculty() {
}
public Faculty (String name, String address, String phone, String email) {
super(name, address, phone, email);
}
public String getOfficeHour() {
return officeHour;
}
public String getRank() {
return rank;
}
public void setOfficeHour(String officeHour) {
this.officeHour = officeHour;
}
public void setRank(String rank) {
this.rank = rank;
}
@Override
public String toString() {
return super.toString() + "\n" + "Office hour: " + officeHour + "\n" + "Rank : " + rank;
}
}
public class Person {
private String name;
private String address;
private String phone;
private String email;
public Person() {
}
public Person(String name, String address, String phone, String email) {
this.name = name;
this.address = address;
this.phone = phone;
this.email = email;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
public String getPhone() {
return phone;
}
public String getEmail() {
return email;
}
public void setName(String name) {
this.name = name;
}
public void setAddress(String address) {
this.address = address;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "Name: " + name + "\n" + "Address: " + address + "\n" +
"Phone: " + phone + "\n" + "Email : " + email;
}
http://www.AssignmentExpert.com

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!
LATEST TUTORIALS
APPROVED BY CLIENTS