Question

In: Computer Science

Write a Java Program using the concept of objects and classes. Make sure you have two...

Write a Java Program using the concept of objects and classes. Make sure you have two files Employee.java and EmployeeRunner.java. Use the template below for ease. (Please provide detailed explanation)

Class Employee

Class Variables:

Name

Work hour per week

Hourly payment

Class Methods:

- Get/Sets

- generateAnnualSalary(int:Duration of employment)

           

  annual salary = Hourly payment * Work hours per week * 50

If the employee is working for more than 5 years,

10% added bonus

           

-void displayAnnualSalary ( )

before and after tax considering there’s an effective 25% tax

Class EmployeeRunner

main method

            - Create an object of type Employee

            - Prompt the user to insert name, work hour per week, hourly payment and duration of

                employment in years

  • Generate annual salary and display the before and after tax amount

Solutions

Expert Solution

Java Program:

File: Employee.java

class Employee
{
   private String name;
   private int workHoursPerWeek;
   private double hourlyPayment;
  
   //Constructor
   public Employee()
   {
       name = "";
       workHoursPerWeek = 0;
       hourlyPayment = 0.0;
   }
  
   //Arg Constructor
   public Employee(String n, int hrs, double pay)
   {
       name = n;
       workHoursPerWeek = hrs;
       hourlyPayment = pay;
   }
  
   //Getter and Setter Methods
   public String getName()
   {
       return name;
   }
   public void setName(String n)
   {
       name = n;
   }
   public int getWorkHoursPerWeek()
   {
       return workHoursPerWeek;
   }
   public void setWorkHoursPerWeek(int hrs)
   {
       workHoursPerWeek = hrs;
   }
   public double getHourlyPayment()
   {
       return hourlyPayment;
   }
   public void setHourlyPayment(double pay)
   {
       hourlyPayment = pay;
   }
  
   //Method that generates Annual Salary
   public double generateAnnualSalary(int duration)
   {
       //Calculating annual salary
       double annualSal = (hourlyPayment * workHoursPerWeek * 50);
      
       //Checking duration
       if(duration > 5)
       {
           //Adding 10% Bonus
           annualSal = annualSal + (annualSal * 0.10);
       }
      
       return annualSal;
   }
  
   //Annual Salary Display
   public void displayAnnualSalary(double annualSal)
   {
       System.out.printf("\nBefore Tax: $%.2f \n", annualSal);
       //Adding tax
       double annualSalWithTax = annualSal + (annualSal*0.25);
       System.out.printf("\nAfter Tax: $%.2f \n", annualSalWithTax);
   }
}

File: EmployeeRunner.java

import java.util.*;

class EmployeeRunner
{
   //Main method
   public static void main(String[] args)
   {
       //Create an object of type Employee
       Employee empObj = new Employee();
      
       //Scanner object
       Scanner reader = new Scanner(System.in);
      
       //Prompting details from user
       System.out.print("Enter Student Name: ");
       String name = reader.nextLine();
       System.out.print("Enter work hour per week: ");
       int hrs = reader.nextInt();
       System.out.print("Enter hourly payment: $");
       double hourlyPay = reader.nextDouble();
       System.out.print("Enter duration of employment in years: ");
       int years = reader.nextInt();
      
       //Assigning values
       empObj.setName(name);
       empObj.setWorkHoursPerWeek(hrs);
       empObj.setHourlyPayment(hourlyPay);
      
       //Generating Annual Salary
       double annualSal = empObj.generateAnnualSalary(years);
      
       //Printing salary
       empObj.displayAnnualSalary(annualSal);
      
       //Closing reader
       reader.close();
   }
}

__________________________________________________________________________________________

Sample Run:


Related Solutions

Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type float. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type float. For each class, provide its getter and setter functions, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write...
Need this program Using Classes , Objects, Save to file, and Printbill Simple python assignment Write a menu-driven program for Food Court. (You need to use functions!) Display the food menu to a user (Just show the 5 options' names and prices - No need to show the Combos or the details!) Ask the user what he/she wants and how many of it. (Check the user inputs) AND Use strip() function to strip your inputs. Keep asking the user until...
Write a java program that creates a hashtable with 10 objects and 5 data members using...
Write a java program that creates a hashtable with 10 objects and 5 data members using mutator and accessor methods for each data member.
[JAVA] You will write a program to validate passwords for users, making sure they meet the...
[JAVA] You will write a program to validate passwords for users, making sure they meet the following criteria: Rules: Passwords must be at least 8 characters long Passwords can only contain alpha numeric characters (no spaces or special characters) Passwords must contain at least 1 uppercase character Passwords must contain at least 1 lowercase character Passwords must contain at least 1 numeric character (0-9) Passwords cannot contain the word “password” A password that does not meet all of these rules...
write a program to make scientific calculator in java
Problem StatementWrite a program that uses the java Math library and implement the functionality of a scientific calculator. Your program should have the following components:1. A main menu listing all the functionality of the calculator.2. Your program should use the switch structure to switch between various options of the calculator. Your Program should also have the provision to handle invalidoption selection by the user.3. Your calculator SHOULD HAVE the following functionalities. You can add any other additional features. PLEASE MAKE...
How do objects enhance Java? How do objects relate to classes and methods?
How do objects enhance Java? How do objects relate to classes and methods?
Write a Java program such that it consists of 2 classes: 1. a class that serves...
Write a Java program such that it consists of 2 classes: 1. a class that serves as the driver (contains main()) 2. a class that contains multiple private methods that compute and display a. area of a triangle (need base and height) b area of a circle (use named constant for PI) (need radius) c. area of rectangle (width and length) d. area of a square (side) e. surface area of a solid cylinder (height and radius of base) N.B....
Write code in java using the LinkedList connecting two different classes. For example, Employee and EmployeeList...
Write code in java using the LinkedList connecting two different classes. For example, Employee and EmployeeList are two different classes that are used to create the assignment.
JAVA PROGRAM (Make sure that programs are running. Please discuss, if there is any compilation or...
JAVA PROGRAM (Make sure that programs are running. Please discuss, if there is any compilation or run error.) Q. 1 Calculate the expression a)         x= 7.0 + (12 %3)*5 – 3;                    b)         x= 7 + (11 / 2)*5 + 3;            Q 2: Write a program that prompts the user to enter five test scores and then prints the average test score. (Assume that the test scores are decimal numbers.) Q 3. Write a program that prompts the capacity, in gallons,...
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The...
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The coin class represents a coin. Any object made from it will have a 1) name, 2) weight and 3) value. As of now, the instance variables in Coin.java are all public, and the main function is calling these variables directly for the one coin made in it. Your goal is to enforce information hiding principles in this project. Take Coin.java, make all instance variables...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT