Question

Hey, I have this Data Structures homework Im struggling to finish. I need to Define a...

Hey, I have this Data Structures homework Im struggling to finish. I need to Define a class Worker derived from Human with fields WeekSalary and WorkHoursPerDay and method MoneyPerHour() that returns the payment earned by hour by the worker. And I have to initialize a list of 10 workers and sort them by payment per hour in descending order. I have already created the super class Human holding a first name and a last name. As Worker extends human.

Please help, Thanks in advance

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

Below is the code for your requirement. Please comment if you face any difficulty.

Code:

===

package com.dont.know;

import java.util.Arrays;

public class WorkersDemo {
   public static void main(String[] args) {
       Worker w1 = new Worker("1", "bbb", 5600, 8);
       Worker w2 = new Worker("2", "ccc", 56000, 8);
       Worker w3 = new Worker("3", "ddd", 560000, 8);
       Worker w4 = new Worker("4", "fff", 5600000, 8);
      
       Worker[] w_arr = new Worker[4];
       w_arr[0] = w1;
       w_arr[1] = w2;
       w_arr[2] = w3;
       w_arr[3] = w4;
       Arrays.sort(w_arr);
       for(int i=0; i<4; i++){
          
           System.out.println(w_arr[i].firstName+" "+w_arr[i].lastName);
       }
   }
}

class Worker extends Human implements Comparable<Worker>{
   int weekSalary = 0, workHoursPerDay = 0, salaryPerHour = 0;
  
   Worker(String firstName, String lastName, int weekSalary, int workHoursPerDay){
       super(firstName, lastName);
       this.weekSalary = weekSalary;
       this.workHoursPerDay = workHoursPerDay;
   }
  

   @Override
   public int compareTo(Worker o1) {
       salaryPerHour = weekSalary/(7*workHoursPerDay);
  
       if(o1.salaryPerHour > this.salaryPerHour){
           return 1;
       }
       else if(o1.salaryPerHour < this.salaryPerHour){
           return -1;
       }
       return 0;
   }
  
}

class Human{
   String firstName;
   String lastName;
  
   Human(String firstName, String lastName){
       this.firstName = firstName;
       this.lastName = lastName;
   }
  
}

Output:

======

Add a comment
Know the answer?
Add Answer to:
Hey, I have this Data Structures homework Im struggling to finish. I need to Define a...
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
  • Hey, I have this homework from my data structures class using java that I am having...

    Hey, I have this homework from my data structures class using java that I am having difficulties coding. I had to create an abstract class Shape, which contains two protected instance variables color(String) and filled(boolean). Getter and setter for all the instance variables, and toString(). Two abstract methods getArea() and getPerimeter(). The part that I am not sure how to code is: for the subclasses of Shape which are Circle and Rectangle I have to override the abstract methods getArea()...

  • Hey, I have an assignment from my Data Structures class. I need the output to be:...

    Hey, I have an assignment from my Data Structures class. I need the output to be: [1] to set the student name [2] to set the student address [3] to set the student GPA [4] to set the student student ID [5] to set the student major [6] to print student info [7] to exit Then I need this output to repeat another 2 times. How can I code that? Its java Also, to code the output above, I used...

  • Ive got this started but im really struggling its a c# program, I have to modify...

    Ive got this started but im really struggling its a c# program, I have to modify the class  Purse  to implement the interface ICloneable . create a main program that demonstrates that the Purse method Clone works. using System; using System.Collections; namespace TestingProject {    /// <summary>    /// A coin with a monetary value.    /// </summary>    public class Coin   {        ///   Constructs a coin.        ///   @param aValue the monetary value of the coin       ...

  • hey! I really am struggling with this homework for nutrition I have questions 1 but I...

    hey! I really am struggling with this homework for nutrition I have questions 1 but I need help on question 2-10. thanks! 9yo male has a follow-up appointment at the pediatric gastroenterologist office. He initially presented w/black, tarry stools and stomach pain. He was diagnosed w/peptic ulcer disease and prescribed antibiotics. Ht: 53" (55th%ile), wt: 72 lbs. (70 %ile). Nutrition related labs: Hgb and Het are below normal values (anemia). All other values are WNL. 1. The RDA for protein...

  • Im struggling with my final assignment and I don’t know how to start. The code has...

    Im struggling with my final assignment and I don’t know how to start. The code has to be done in python using tkinter module. I would very appreciate the help thank you QUESTION 1 Write a program that counts the number of names on a list. The program must include a class named FinalProjectlastName with the following attributes (class variables) and functions: Name: FinalProjectLastName Attributes: names: list of strings that stores names count: number of names on the list. Functions:...

  • Java Description Write a program to compute bonuses earned this year by employees in an organization....

    Java Description Write a program to compute bonuses earned this year by employees in an organization. There are three types of employees: workers, managers and executives. Each type of employee is represented by a class. The classes are named Worker, Manager and Executive and are described below in the implementation section. You are to compute and display bonuses for all the employees in the organization using a single polymorphic loop. This will be done by creating an abstract class Employee...

  • I need just homework#6, I post homework# 5 to understand how to do it ? Please...

    I need just homework#6, I post homework# 5 to understand how to do it ? Please do it and please don't copy the answer CSCE 1030 Homework 5 Due: 11:59 PM on Monday, April 17,2017 PROGRAM DESCRIPTION: In this C++ program, you will start building the software infrastructure that will allow you to play a simplified version of the class game of Minesweeper that will display to the screen. In Homework 6, you will continue the work begun here to...

  • This is a simple program that I'm struggling with. Java is not my forte... It's way...

    This is a simple program that I'm struggling with. Java is not my forte... It's way too verbose for my liking. Anyways... The criteria for the prog is as follows: No issues with the GUI, I can do this on my own, but for a reference see the following: A combo box should allow the user to select one of the four database actions shown. The database should be implemented as a HashMap, with the ID field as the key...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • Need help finishing this code # Description : The Pet class contains fields for name, pet...

    Need help finishing this code # Description : The Pet class contains fields for name, pet # type,and age. The age field is the age now # or age of pet when it passed away. (These # are all dogs I have had.) There is a static or # class variable called number_pets that # tracks how many instances have been created. # The constructor will fill all fields and add # one to the number_pets variable. # The special...

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