Question

In: Computer Science

Java Coding Part A Create a class Employee. Employees have a name.   Also give Employee a...

Java Coding

Part A

Create a class Employee. Employees have a name.   Also give Employee a method paycheck() which returns a double. For basic employees, paycheck is always 0 (they just get health insurance). Give the class a parameterized constructor that takes the name;

Add a method reportDeposit. This method prints a report for the employee with the original amount of the paycheck, the amount taken out for taxes (we will do a flat 17%), and the final amount (for basic employees this will just be a lot of 0's but make sure to do the math based on what paycheck returns).  

Salaried employees are employed either for 10 or 12 months of the year for some salary. Their paycheck is their salary, divided up into two pays a month for however many months they are employed.

Using inheritance, create a class for this type of employee (more will be added in part B). Don't override reportDeposit. Give a parameterized constructor for name and salary that chains back to the parameterized superclass constructor.

In a main, create an array of employees, and set it up with some of each kind, some with different values. (hint: you've got parameterized constructors...) Loop through the list and call reportDeposit for each employee, also find the employee with the highest paycheck.

Part B  

Hourly employees have an hourly wage, and a number of hours they are scheduled to work per week,. One paycheck is based on two weeks of work (they are guaranteed to have the same hours for both weeks). They are paid an extra 5% of their hourly rate for each hour over 40 hours per week they are scheduled.

Adjunct employees may teach up to 18 credits, and are paid $827 per credit, with the total spread across 2 paychecks a month for 4 months.

Add classes for these types of employee.

Add two hourly and two adjunct employees to your array in main. You shouldn't have to change anything else in main.

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

import java.util.*;
import java.util.Scanner;

class Employee {
  String name;

  Employee(String a) {
    name = a;
  }

  double paycheck() {
    return 0;
  }

  void reportDeposit() {
    double taxes = 0.17 * paycheck();
    System.out.printf("Original amount of paycheck: %.2f\n", paycheck());
    System.out.printf("Amount deducted in taxes: %.2f\n", taxes);
    System.out.printf("Final amount: %.2f\n", paycheck() - taxes);
  }
}

class Salaried extends Employee {
  double salary;

  Salaried(String name, double s) {
    super(name);
    salary = s;
  }

  @Override
  double paycheck() {
    return salary;
  }
}

class Hourly extends Employee {
  double wage;
  int hours;

  Hourly(String name, double w, int h) {
    super(name);
    wage = w;
    hours = h;
  }

  @Override
  double paycheck() {
    double pc = 2 * hours * wage;
    double bonus = 0;
    if (hours > 40) {
      bonus = 2 * (hours - 40) * (wage + 0.05 * wage);
    }
    return pc + bonus;
  }
}

class Adjunct extends Employee {
  int credits;

  Adjunct(String name, int c) {
    super(name);
    credits = c;
  }

  @Override
  double paycheck() {
    return 827 * credits;
  }
}

class MyClass {

  public static void main(String[] args) {
    Employee[] arr = new Employee[4];
    arr[0] = new Employee("abc");
    arr[1] = new Salaried("xyz", 400);
    arr[2] = new Hourly("pqr", 40, 45);
    arr[3] = new Adjunct("ijk", 16);
    for (int i = 0; i < arr.length; i++) {
      arr[i].reportDeposit();
    }
  }
}

Related Solutions

Part C (25 pts) Coding question Create a Java class name Store_XXXXX with last 5 digits...
Part C (25 pts) Coding question Create a Java class name Store_XXXXX with last 5 digits of your student ID and write your code in there. A PC store sells many types of computers. The PC can have either 16 or 8 gigabytes of memory. The quality of the PCs can be either New, Refurbished, or Dented. The price list is given as follows: Memory size/Status New Refurbished Dented 16 gigabytes 849.99 729.99 609.99 8 gigabytes 699.99 579.99 439.99 Determine...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for the following: 1. Name the class SalonServices 2. Add private data fields: a. salonServiceDescription – This field is a String type b. price - This field is a double type 3. Create two methods that will set the field values. a. The first method setSalonServiceDescription() accepts a String parameter defined as service and assigns it to the salonServiceDescription. The method is not static b....
Java Coding Background You will create a Java class that simulates a water holding tank. The...
Java Coding Background You will create a Java class that simulates a water holding tank. The holding tank can hold volumes of water (measured in gallons) that range from 0 (empty) up to a maximum. If more than the maximum capacity is added to the holding tank, an overflow valve causes the excess to be dumped into the sewer system. Assignment The class will be named HoldingTank. The class attributes will consist of two int fields – current and maxCapacity....
JAVA CODING PLEASE Create a class SportsCar that inherits from the Car class (CAR CLASS LISTED...
JAVA CODING PLEASE Create a class SportsCar that inherits from the Car class (CAR CLASS LISTED BELOW THIS QUESTION). Include the following: A variable Roof that holds the type of roof (Ex: Convertible, Hard-Top, Soft-Top) A variable Doors that holds the car’s number of doors (Ex: 2, 4) Implement the ChangeSpeed method to add 20 to the speed each time it is called. Add exception handling to the ChangeSpeed method to keep the speed under 65. Implement the sound method...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after a Cat. You should have instance variables as follows: The Cat’s name The number of mice caught by the Cat. Whether or not the Cat is secretly plotting to kill you Note that you will need to choose both good types and meaningful identifiers for each of these instance variables. You may also assume that the Cat is not automatically always secretly plotting to...
Create java class with name BaseballPlayer Instructions for BaseballPlayer class: The BaseballPlayer class is modeled after...
Create java class with name BaseballPlayer Instructions for BaseballPlayer class: The BaseballPlayer class is modeled after a BaseballPlayer and will contain methods to calculate various statistics based on the stats of a player. For this class, you will want to use a static variable for storing a DecimalFormat object. See the API document for the BaseballPlayer class for a list of methods you will write. API Document Constructors: Identifier: BaseballPlayer(String name, int number, int singles, int doubles, int triples, int...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods designed to perform simple conversions. Specifically, you will be writing methods to convert temperature between Fahrenheit and Celsius and length between meters and inches and practicing overloading methods. See the API document for the Conversion class for a list of the methods you will write. Also, because all of the methods of the Conversion class will be static, you should ensure that it is...
Part A Java netbeans ☑ Create a project and in it a class with a main....
Part A Java netbeans ☑ Create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class , after the package statement, paste import java.util.Scanner; As the first line inside your main method, paste Scanner scan = new Scanner(System.in); Remember when you are getting a value from the user, first print a request, then use the Scanner to read the right type...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT