Question

In order to do Program 6, Program 5 should be modified.

Program 6

-----------------------------------

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

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 [email protected] 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: [email protected] 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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("[email protected]");
       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 ");
   }

}

OUTPUT:

name: unknown, age: -1, email: none
name: demo_s2, age: 23, email: [email protected]
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

Add a comment
Know the answer?
Add Answer to:
In order to do Program 6, Program 5 should bemodified.Program 6
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
  • Build a java program that has Student class, use arrays of objects {name, age, gpa} to...

    Build a java program that has Student class, use arrays of objects {name, age, gpa} to saves 3 students records. Use printable interface with abstract print method. Student class inherits from an abstract Person class that has name, age as attributes. It also has the following 2 methods: abstract setAge and concrete setGPA. Below is the hierarchy and a sample run (using netbeans): Hierarchy: Printable Interface print(Object ( ) ): object ] Abstract Person Class Name: String Age: int Abstract...

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

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

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

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • Last picture is the tester program! In this Assignment, you will create a Student class and...

    Last picture is the tester program! In this Assignment, you will create a Student class and a Faculty class, and assign them as subclasses of the superclass UHPerson. The details of these classes are in the UML diagram below: UHPerson - name : String - id : int + setName(String) : void + getName(): String + setID(int) : void + getID(): int + toString(): String Faculty Student - facultyList : ArrayList<Faculty - rank: String -office Hours : String - studentList...

  • Given attached you will find a file from Programming Challenge 5 of chapter 6 with required...

    Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...

  • Instructions: Consider the following C++ program. At the top you can see the interface for the...

    Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...

  • Using Python. 3) Create a single-linked list (StudentList) where the data in the link is an object of type pointer to Student as defined below. Note that you need to store and pass a pointer of type...

    Using Python. 3) Create a single-linked list (StudentList) where the data in the link is an object of type pointer to Student as defined below. Note that you need to store and pass a pointer of type Student so that you do not create duplicate objects. Test your list with the provided program. You will find example code for a single-linked list of integers in Moodle that you can base your solution on. For your find methods, you can either...

  • CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!)....

    CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!). Can be resubmitted up to two times until Session 6 if your first version is submitted by session 3. In this project, you create two classes for tracking students. One class is the Student class that holds student data; the other is the GradeItem class that holds data about grades that students earned in various courses. Note: the next three projects build on this...

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