Question

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 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 five hourly workers (Use the scanner to input user information), creates an arraylist of 5 hourly cworker objects, display the attributes and billing for each of the five hourly workers. Display the worker name and billing amount for each worker and the total billing amount for all five .workers combined.

.

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

import java.util.*;

class Worker{
   protected String Name, Worker_ID, Worker_Address, Worker_City, Worker_State;
   Worker(){
       Name = "name";
       Worker_ID = "123";
       Worker_Address = "xyz";
       Worker_City = "city";
       Worker_State = "pqr";
   }
}
class HourlyWorker extends Worker{
   int hourlySalary, billableHours, billing_amount;
   HourlyWorker(){
       super(); //calling constructor of Worker class
       hourlySalary = 0;
       billableHours = 0;
   }
   //calculating the amount due
   public void billing(){
       billing_amount = hourlySalary * billableHours;
   }
}

public class Test{
       public static void main(String args[]){
           int total_amount=0;
           Scanner sc = new Scanner(System.in);

           HourlyWorker hw[] = new HourlyWorker[10];
           System.out.println("Input for 5 hourly workers:\n");
           for(int i=0;i<5;i++){
               System.out.println("For worker :"+(i+1));
               //input all attributes
               System.out.print("Enter name: ");
               hw[i].Name = sc.nextLine();
               System.out.print("Enter ID: ");
               hw[i].Worker_ID = sc.nextLine();
               System.out.print("Enter Address: ");
               hw[i].Worker_Address = sc.nextLine();
               System.out.print("Enter city: ");
               hw[i].Worker_City = sc.nextLine();
               System.out.print("Enter state: ");
               hw[i].Worker_State = sc.nextLine();
               System.out.print("Enter hourly salary: ");
               hw[i].hourlySalary = Integer.parseInt(sc.nextLine());
               System.out.print("Enter billable hours: ");
               hw[i].billableHours = Integer.parseInt(sc.nextLine());
               hw[i].billing();
           }
           //displaying all worker details
           System.out.println("Worker details:\n");
           for(int i=0;i<5;i++){
               System.out.println("Worker "+(i+1));
               System.out.println("NAME: "+hw[i].Name+"\nWorker ID: "+hw[i].Worker_ID+"\nAddress: "+hw[i].Worker_Address);
               System.out.println("City: "+hw[i].Worker_City+"\nState: "+hw[i].Worker_State+"\nBilling amount: "+hw[i].billing_amount);
               total_amount += hw[i].billing_amount;
           }
           System.out.println("Total billing amount: "+total_amount);
       }
}

Add a comment
Know the answer?
Add Answer to:
In Java Create a class Worker. Your Worker class should include the following attributes as String...
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 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...

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

  • Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...

    Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string SSN; The Employee class has ▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes. ▪ a constructor with parameters for each of the attributes ▪ getter and setter methods for each of the private attributes ▪ a method getFullName() that returns the last name, followed by a...

  • python code? 1. Create a class called Person that has 4 attributes, the name, the age,...

    python code? 1. Create a class called Person that has 4 attributes, the name, the age, the weight and the height [5 points] 2. Write 3 methods for this class with the following specifications. a. A constructor for the class which initializes the attributes [2.5 points] b. Displays information about the Person (attributes) [2.5 points] c. Takes a parameter Xage and returns true if the age of the person is older than Xage, false otherwise [5 points] 3. Create another...

  • Project 2 Tasks: Create a Coin.java class that includes the following:             Takes in a coin...

    Project 2 Tasks: Create a Coin.java class that includes the following:             Takes in a coin name as part of the constructor and stores it in a private string             Has a method that returns the coins name             Has an abstract getvalue method Create four children classes of Coin.java with the names Penny, Nickle, Dime, and Quarter that includes the following:             A constructor that passes the coins name to the parent             A private variable that defines the...

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

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

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

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