Question

You will be writing a multiclass user management system using the java. Create a program that implements a minimum of four cl write in java and please code the four classes with the requirements instructed
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.ArrayList;

class Employee {
   private String name;
   private String department;
   private String id;
   private Address address;
   private Contact contact;
  

   // Default constructor. Set protected variables to the empty string or 0
   public Employee() {
       name = "";
       department = "";
       id = "";
   }

   // Constructor with parameters to set the private variables
   public Employee(String name, String department, String id,Address a, Contact c) {
       this.name = name;
       this.department = department;
       this.id = id;
       address=a;
       contact=c;
   }

   public String getName() {
       return name;
   }

   public String getDepartment() {
       return department;
   }

   public String getId() {
       return id;
   }

   public void setDepartment(String department) {
       this.department = department;
   }

   public double getWeeklyPay() {
       return 0.0;
   }

   public String toString() {
       return "Name: " + name + ", Department: " + department + ", ID: " + id;
   }
}
class Address{
   private String streetAddress;
   private String city;
   private String state;
   private String pinCode;
   public Address(){}
   public Address(String aStreetAddress, String aCity, String aState, String aPinCode) {
       super();
       streetAddress = aStreetAddress;
       city = aCity;
       state = aState;
       pinCode = aPinCode;
   }
   @Override
   public String toString() {
       return "Address [streetAddress=" + streetAddress + ", city=" + city + ", state=" + state + ", pinCode="
               + pinCode + "]";
   }
   public String getStreetAddress() {
       return streetAddress;
   }
   public void setStreetAddress(String aStreetAddress) {
       streetAddress = aStreetAddress;
   }
   public String getCity() {
       return city;
   }
   public void setCity(String aCity) {
       city = aCity;
   }
   public String getState() {
       return state;
   }
   public void setState(String aState) {
       state = aState;
   }
   public String getPinCode() {
       return pinCode;
   }
   public void setPinCode(String aPinCode) {
       pinCode = aPinCode;
   }
  
}
class Contact{
   private String email;
   private String phone;
   Contact(){
      
   }
   public Contact(String aEmail, String aPhone) {
       super();
       email = aEmail;
       phone = aPhone;
   }
   public String getEmail() {
       return email;
   }
   public void setEmail(String aEmail) {
       email = aEmail;
   }
   public String getPhone() {
       return phone;
   }
   public void setPhone(String aPhone) {
       phone = aPhone;
   }
   @Override
   public String toString() {
       return "Contact [email=" + email + ", phone=" + phone + "]";
   }
  
  
}
class HourlyEmployee extends Employee {

   private double hourlyRate;

   /* FIXME(2) Complete the default constructor to set hourlyRate to 0.0 */

   public HourlyEmployee() {

       super();
       hourlyRate = 0.0;

   }

   /*
   * FIXME(3) Complete the argumented constructor to set each field properly
   *
   * Note that you can call the superclass constructor to initialize the
   * fields defined in the superclass
   *
   * The second video in Canvas shows an example on this.
   */

   public HourlyEmployee(String name, String department,

           String id, double rate,Address a , Contact c) {

       super(name, department, id,a,c);

       setHourlyRate(rate);

   }


   public double getHourlyRate() {

       return hourlyRate;

   }

   public void setHourlyRate(double rate) {

       hourlyRate = (rate < 0.0) ? 0.0 : rate;

   }


   @Override

   public String toString() {

       return "hourly employee: "

               + super.toString()

               + String.format(" hourly wage: $%.2f\n",

                       getHourlyRate());

   }

}

class SalariedEmployee extends Employee {
   private double annualSalary;

   public SalariedEmployee() {
       annualSalary=0;
   }

   public SalariedEmployee(String name, String department, String id, double salary,Address a,Contact c) {
       super(name, department, id,a,c);  
       annualSalary=salary;
   }

   public double getAnnualSalary() {
       return annualSalary;
   }

   public void setAnnualSalary(double salary) {
       this.annualSalary = salary;
   }

   @Override
   public double getWeeklyPay() {
       return annualSalary / 52;
   }

   @Override
   public String toString() {
       return "Name : " + getName() + " Department : " + getDepartment() + " ID : " + getId() + ", Annual Salary : $"
               + getAnnualSalary();
   }

}

public class HumanResource {
   public static void main(String[] args) {
       ArrayList<Employee> employees = new ArrayList<Employee>();

       HourlyEmployee e1 = new HourlyEmployee("John Smith", "Sales", "jsmith1", 18.2,new Address(),new Contact());
       employees.add(e1);
       SalariedEmployee e2 = new SalariedEmployee("Amy Brown", "Marketing", "abrown3", 45000,new Address(),new Contact());
       employees.add(e2);
       SalariedEmployee e3 = new SalariedEmployee("Henry Chuck", "Accounting", "cchuck2", 50000.0,new Address(),new Contact());
       employees.add(e3);
       SalariedEmployee e4 = new SalariedEmployee("Mary Miller", "IT", "mmiller5", 75000,new Address(),new Contact());
       employees.add(e4);

       for (int i = 0; i < employees.size(); i++) {
           System.out.println(employees.get(i).getName() + " $" + employees.get(i).getWeeklyPay());
       }
   }
}

Add a comment
Know the answer?
Add Answer to:
write in java and please code the four classes with the requirements instructed You will be...
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
  • My Java code from last assignment: Previous Java code: public static void main(String args[]) { //...

    My Java code from last assignment: Previous Java code: public static void main(String args[]) { // While loop set-up boolean flag = true; while (flag) { Scanner sc = new Scanner(System.in); // Ask user to enter employee number System.out.print("Enter employee number: "); int employee_number = sc.nextInt(); // Ask user to enter last name System.out.print("Enter employee last name: "); String last_name = sc.next(); // Ask user to enter number of hours worked System.out.print("Enter number of hours worked: "); int hours_worked =...

  • My Java code from last assignment: Previous Java code: public static void main(String args[]) { //...

    My Java code from last assignment: Previous Java code: public static void main(String args[]) { // While loop set-up boolean flag = true; while (flag) { Scanner sc = new Scanner(System.in); // Ask user to enter employee number System.out.print("Enter employee number: "); int employee_number = sc.nextInt(); // Ask user to enter last name System.out.print("Enter employee last name: "); String last_name = sc.next(); // Ask user to enter number of hours worked System.out.print("Enter number of hours worked: "); int hours_worked =...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Write a Java application with a class name of Payroll, for the “Travel Agency”, that willCalculate...

    Write a Java application with a class name of Payroll, for the “Travel Agency”, that willCalculate the weekly paycheck for both Salaried and Hourly employees. Salaried employees will be paid 1/52 of their annual pay minus 18% withheld for federal and state taxes, as well as 4% for retirement pension. Salaried employees do not collect overtime pay. There are two types of Hourly employees; permanent employees and temporary weekly employees. •Permanent weekly employees will be paid their hourly rate minus...

  • In Java Kindly be sure to take in user input and store the 3 worker classes...

    In Java Kindly be sure to take in user input and store the 3 worker classes in an ArrayList Create a class Worker. Your Worker class should include the following attributes as String variables: Name, Worker ID, Worker Address, Worker City, Worker State Create the constructor that initializes the above worker attributes. Then make another class name HourlyWorker that inherits from the Worker class.   HourlyWorker has to use the inherited parent class variables and add in hourlySalary and billableHours. Your...

  • java Payroll class Exceptions Programming Challenge 5 of Chapter 6 required you to write a Payroll...

    java Payroll class Exceptions Programming Challenge 5 of Chapter 6 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 for the employee’s ID number. If you implemented this field as a string, then an empty string would be invalid. If you implemented this field as a numeric variable, then a negative number or...

  • JAVA :The following are descriptions of classes that you will create. Think of these as service...

    JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...

  • Create the Python code for a program adhering to the following specifications. Write an Employee class...

    Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...

  • (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE...

    (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE OR THE OTHER) Design an Employee class that fields for the following pieces of information: 1) Employee name 2) Employee number Next design a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to hold the following information: 1) Shift number (an integer, such as 1, 2, or 3) 2)Hourly pay The workday is divided into two shifts day...

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