Question

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 HourlyWorker class should contain a constructor that calls the constructor from the Worker class to initialize the common instance variables but also initializes the hourlySalary and billableHours. Next create a billing method to HourlyWorker that will calculate the amount due.  

FInally, create a test class that prompts the user for the information for three hourly workers (Use the scanner to input user information), creates an arraylist of 3 hourly worker objects, display the attributes and billing for each of the three hourly workers via output.. Display the worker name and billing amount for each worker and the total billing amount for all three.workers combined.

The output must be a printed version of ArrayList.

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

Worker.java


public class Worker {

   private String workerId, workerName, workerCity, workerState, workerAddress;

   public Worker() {
      
   }
  
   public Worker(String workerId, String workerName, String workerCity, String workerState, String workerAddress) {
       this.workerId = workerId;
       this.workerName = workerName;
       this.workerCity = workerCity;
       this.workerState = workerState;
       this.workerAddress = workerAddress;
   }

   // getters and setters used to access the private data members of the class.

   public String getWorkerId() {
       return workerId;
   }

   public void setWorkerId(String workerId) {
       this.workerId = workerId;
   }

   public String getWorkerName() {
       return workerName;
   }

   public void setWorkerName(String workerName) {
       this.workerName = workerName;
   }

   public String getWorkerCity() {
       return workerCity;
   }

   public void setWorkerCity(String workerCity) {
       this.workerCity = workerCity;
   }

   public String getWorkerState() {
       return workerState;
   }

   public void setWorkerState(String workerState) {
       this.workerState = workerState;
   }

   public String getWorkerAddress() {
       return workerAddress;
   }

   public void setWorkerAddress(String workerAddress) {
       this.workerAddress = workerAddress;
   }

   public String toString() {
       return "Worker id: " + this.workerId + ", Worker name: " + this.workerName + ", Worker Address: "
               + this.workerAddress + ", Worker City: " + this.workerCity + ", State: " + this.workerState;
   }
}

HourlyWorker.java


public class HourlyWorker extends Worker{
   private double HourlySalary, billableHours;

   public HourlyWorker() {
      
   }
  
   public HourlyWorker(String workerId, String workerName, String workerCity, String workerState,
           String workerAddress, double hourlySalary, double billableHours)
   {
       super(workerId, workerName, workerCity, workerState, workerAddress);
       this.HourlySalary = hourlySalary;
       this.billableHours = billableHours;
   }
  
   public double getAmountDue() {
       return this.HourlySalary * this.billableHours;
   }
  
   public String toString() {
      
       //super.toString() will execute the toString() method of super class that is HourlyWorker
       return super.toString() + ", Amount Due: " + this.getAmountDue();
   }
}

WorkerMain.java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class WorkerMain {
   public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
       String id, name, city, address, state;
       double hours, wagesPerHour;
      
       Worker obj = null;
       List<Worker> workers = new ArrayList<>();
      
       // read information of 3 objects
       for(int i = 0 ; i < 3 ; i++)
       {
           System.out.printf("Worker %d:\nEnter id: ", i+1);
           id = in.nextLine();
          
           System.out.print("Enter name: ");
           name = in.nextLine();
          
           System.out.print("Enter address: ");
           address = in.nextLine();
          
           System.out.print("Enter city: ");
           city = in.nextLine();
          
           System.out.print("Enter state: ");
           state = in.nextLine();
      
           System.out.print("Enter hours worked: ");
           hours = in.nextDouble();
           in.nextLine();           // clear the buffer
          
           System.out.print("Enter wages per hour: ");
           wagesPerHour = in.nextDouble();
           in.nextLine();
          
           obj = new HourlyWorker(id, name, city, state, address, wagesPerHour, hours);
           // add object to ArrayList
           workers.add(obj);
          
           System.out.println("---------------------------------");
       }
      
       // print workers information
      
       for(Worker worker: workers)
       {
           System.out.println(worker);
       }
      
       in.close();
   }
}

Output:

Add a comment
Know the answer?
Add Answer to:
In Java Kindly be sure to take in user input and store the 3 worker classes...
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
  • In Java Create a class Worker. Your Worker class should include the following attributes as String...

    In Java 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 HourlyWorker class should contain a constructor that calls the constructor from the Worker class to initialize the...

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

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • (To be written in Java code) Create a class named CollegeCourse that includes the following data...

    (To be written in Java code) Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the department (for example, ENG) id (int) - the course number (for example, 101) credits (double) - the credits (for example, 3) price (double) - the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display()...

  • Programming: Create a class called City with two public variables: a string to store the name...

    Programming: Create a class called City with two public variables: a string to store the name of the city and a float to store the average temperature in Fahrenheit. Create one object of the class that you create and ask the user to enter the city name and the average temperature in Fahrenheit. Store these in the object of the class that you create. Then display the contents of the class. Once that is working, make the variables private and...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • Must be in Java. Please show step by step process with proper explanation and comments. Please...

    Must be in Java. Please show step by step process with proper explanation and comments. Please maintain proper indentation. CODE PROVIDED: Doctor.java HospitalDoctor.java Q1Runner.java import java.util.Scanner; public class Q1Runner { public static void main(String[] args) { Scanner kb = new Scanner(System.in);               // Do your work here        } } You are asked to create the starting point of a system to represent several types of medical doctors. You decided to implement two classes: a superclass...

  • Implement a Java program using simple console input & output and logical control structures such that...

    Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...

  • Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate....

    Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate. ·         The application calculates the interest amount and formats the loan amount, interest rate, and interest amount. Then, it displays the formatted results to the user. ·         The application prompts the user to continue. ·         The program stops prompting the user for values after taking 3 loan amounts. ·         The application calculates and displays the total loan and interest amount and ends the program Example Output Welcome to...

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