Question

In: Computer Science

JAVA code - please answer all prompts as apart of the same java program with Polymorphism...

JAVA code - please answer all prompts as apart of the same java program with Polymorphism

Classwork

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

Heres the code 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;
    }
}
public 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();
        }
    }
}

And hers the sample output:

Original amount of paycheck: 0.00
Amount deducted in taxes: 0.00
Final amount: 0.00
Original amount of paycheck: 400.00
Amount deducted in taxes: 68.00
Final amount: 332.00
Original amount of paycheck: 4020.00
Amount deducted in taxes: 683.40
Final amount: 3336.60
Original amount of paycheck: 13232.00
Amount deducted in taxes: 2249.44
Final amount: 10982.56


Related Solutions

JAVA programming- please answer all prompts as apart of the same java project Enums enumeration values()...
JAVA programming- please answer all prompts as apart of the same java project Enums enumeration values() and other utilities Part A Create an enumeration AptType representing several different types of apartment. Each type of apartment has a description, a size (square footage), and a rent amount. In the enumeration, provide public final instance variables for these. Also write a parameterized constructor that sets the values of these variables (doing this is just part of seeing up the enum) The apartment...
JAVA programming - please answer all prompts as apart of 1 java assignment. Part A Create...
JAVA programming - please answer all prompts as apart of 1 java assignment. Part A Create a java class InventoryItem which has a String description a double price an int howMany Provide a copy constructor in addition to other constructors. The copy constructor should copy description and price but not howMany, which defaults to 1 instead. In all inheriting classes, also provide copy constructors which chain to this one. Write a clone method that uses the copy constructor to create...
JAVA programming Classwork- please answer all prompts as apart of one java programming project Part A...
JAVA programming Classwork- please answer all prompts as apart of one java programming project Part A Add to your project this class Position, which has x and y coordinates. Create an abstract class GameElt, which has a String name, an int health (keep it in the range 0 to 100) and a Position pos. For GameElt, include a default constructor that starts pos at (0, 0), and a parameterized constructor that takes x and y coordinates and a name. health...
JAVA programming - please ONLY answer prompts with java code *Inheritance* will be used in code...
JAVA programming - please ONLY answer prompts with java code *Inheritance* will be used in code Classwork A zoo is developing an educational safari game with various animals. You will write classes representing Elephants, Camels, and Moose. Part A Think through common characteristics of animals, and write a class ZooAnimal. ☑ ZooAnimal should have at least two instance variables of different types (protected), representing characteristics that all animals have values for. ☑ It should also have at least two methods...
JAVA programming- answer prompts as apart of one java assignment Static static variables static methods constants...
JAVA programming- answer prompts as apart of one java assignment Static static variables static methods constants Create a class Die representing a die to roll randomly. ☑ Give Die a public final static int FACES, representing how many faces all dice will have for this run of the program. ☑ In a static block, choose a value for FACES that is a randomly chosen from the options 4, 6, 8, 10, 12, and 20. ☑ Give Die an instance variable...
I need to make this into a Java Code: Write a program that prompts the user...
I need to make this into a Java Code: Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate: circleCircumference = 2πr circleArea = πr2 sphereArea = 4πr2 sphereVolume = 43πr3 You must use π as defined in the java.lang.Math class. Your prompt to the user to enter the number of days must be: Enter radius: Your output must be of the format: Circle Circumference = circleCircumference Circle Area...
Can you provide java code for a program that prompts the user by asking "How many...
Can you provide java code for a program that prompts the user by asking "How many one mile races have you ran?". After the user inputs how many one mile races have they run it then prompts the user to input how many seconds it took for them to finish each race. So for example, if the user ran 6 races then the user will have to input 6 race times. Is there a way when you prompt the user...
Please code C# 8. Write a program that prompts the user to enter an integer. The...
Please code C# 8. Write a program that prompts the user to enter an integer. The program then determines and displays the following: Whether the integer is divisible by 5 and 6 Whether the integer is divisible by 5 or 6
This is an entry to Java Question. Please answer with Pseudocode and Java code for better...
This is an entry to Java Question. Please answer with Pseudocode and Java code for better understanding. We are mainly using basic in and out declarations and are focusing on API for method invocations. Any help would be very appreciated :) Problem 7: Distance (10 points) Use API (Data Science) Data Science is an emergent field from Computer Science with applications in almost every domain including finances, medical research, entertainment, retail, advertising, and insurance. The role of a data analyst...
In Java please: 3.39 Lab 6e: CharacterOps Write a program that prompts the user to enter...
In Java please: 3.39 Lab 6e: CharacterOps Write a program that prompts the user to enter their first name. Say hello to the person. Then display whether their name begins with a vowel or consonant. If it is neither, perhaps a special character or a number digit, then print neither a vowel nor a consonant. Example 1: Enter your first name: Barbara Hello, Barbara! The first letter of your name, 'B', is a consonant. Example 2: Enter your first name:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT