In order to do Program 6, Program 5 should be modified. Program 6 --------------
ID: 3836362 • Letter: I
Question
In order to do Program 6, Program 5 should be modified.
Program 6
---------------------------------------------------------------------------------------------------------------------------------------------------------
Program 4
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(abstract class exception handling) Modify program4 to meet the following requirements: I. Make Person, Employee classes to abstract classes. Cl0%) 2. Add an interface interface working with a method teach() (5%) interface working void teach(String course) J 3. Modify Faculty class. (20%) a. a private data field and implement existing b. Modify Faculty class as a subclass of addition to the c. toString or print Info) method to print out course d. information, and use method to Modify existing Faculty constructor to accept course dept, String assign the input course. (Hint: Faculty String name, double salary, String course) 4. Handle exceptions in Employee salary (0%) If salary are negative, handle the exception by append "Owith invalid salary" to name. ref: slide day23) 5. Modify test program to assign course to Faculty objects. (5%) 6. Write a test program to create two Students and two Faculties, assign (NOT read from console) the following information, and invokes their printInfo methods. xxxx is your Kean ID. A Student object name: unknown, age: -1, email: none A Student object name: "demo s2", age: 23, email xyz@gmail.com A Faculty object name: "demo fi", salary: 0, dept: none, course: none A Faculty object name: "demo f2", salary: -10000, dept: "CS" course: CPS2231 7. Your program output should look like below: Student name: unknown, age: -1, Email: none Student name: demo s2, age: 23, Email: xyz@gmail.com Faculty name: demo fl, salary: 0.0, dept: none, course: none Faculty name: demo f20 with invalid salary), salary: 0.0, dept: Cs, course: CPS2231 Program6 is developed by kyour Kean email ID>. This project should be coded in ONE java file.Explanation / Answer
PROGRAM CODE:
package util;
interface working
{
void teach(String course);
}
abstract class Person
{
String name;
public Person() {
name = "unknown";
}
public Person(String name) {
this.name = name;
}
public void printInfo()
{
System.out.print("name: " + name);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
abstract class Employee extends Person
{
double salary;
public Employee() {
super();
salary = 0;
}
public Employee(String name, double salary) {
super(name);
if(salary<0)
{
setName(getName() + "(with invalid salary)");
salary = 0.0;
}
else this.salary = salary;
}
@Override
public void printInfo() {
super.printInfo();
System.out.print(", salary: " + salary);
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
if(salary<0)
{
setName(getName() + "(with invalid salary)");
salary = 0.0;
}
else this.salary = salary;
}
}
class Faculty extends Employee implements working
{
private String dept;
private String course;
public Faculty() {
super();
dept = "none";
course = "none";
}
public Faculty(String name, double salary, String dept, String course)
{
super(name, salary);
this.dept = dept;
this.course = course;
}
@Override
public void printInfo() {
super.printInfo();
System.out.println(", dept: " + dept + ", course: " + course);
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
@Override
public void teach(String course) {
this.course = course;
}
}
class Student extends Person
{
int age;
String email;
public Student() {
age = 0;
email = "none";
}
@Override
public void printInfo() {
super.printInfo();
System.out.println(", age: " + age + ", email: " + email);
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
public class ClassManagementSystem {
public static void main(String[] args) {
Student student1 = new Student();
student1.setAge(-1);
student1.printInfo();
Student student2 = new Student();
student2.setName("demo_s2");
student2.setAge(23);
student2.setEmail("xyz@mail.com");
student2.printInfo();
Faculty faculty1 = new Faculty();
faculty1.setName("demo_f1");
faculty1.printInfo();
Faculty faculty2 = new Faculty();
faculty2.setName("demo_f2");
faculty2.setSalary(-1);
faculty2.setDept("CS");
faculty2.teach("CPS2231");
faculty2.printInfo();
System.out.println("Program is developed by <enter yourname>");
}
}
OUTPUT:
name: unknown, age: -1, email: none
name: demo_s2, age: 23, email: xyz@mail.com
name: demo_f1, salary: 0.0, dept: none, course: none
name: demo_f2(with invalid salary), salary: 0.0, dept: CS, course: CPS2231
Program is developed by <enter yourname>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.