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.
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel....
Writing Classes I Write a Java program containing two classes: Dog and a driver class Kennel. A dog consists of the following information: • An integer age. • A string name. If the given name contains non-alphabetic characters, initialize to Wolfy. • A string bark representing the vocalization the dog makes when they ‘speak’. • A boolean representing hair length; true indicates short hair. • A float weight representing the dog’s weight (in pounds). • An enumeration representing the type...
Use JAVA language. Using the switch method concept create a program in which you have an...
Use JAVA language. Using the switch method concept create a program in which you have an artist (singer) and the list of his or her songs. Add 18 songs. Then alter the script to achieve the following in each test run: a) Print all the songs. b) Print only song 15. c) Print only song 19.
[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...
Assignment 1: JAVA Classes, Objects, and Constructors The goal of this assignment is to get you...
Assignment 1: JAVA Classes, Objects, and Constructors The goal of this assignment is to get you familiar with some of the most used JAVA syntax, as well as constructors objects, objects calling other objects, class and instance attributes and methods. You will create a small program consisting of Musician and Song classes, then you will have Musicians perform the Songs. Included is a file “Assignment1Tester.java”. Once you have done the assignment and followed all instructions, you should be able to...
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?
For this assignment you will write a Java program using a loop that will play a...
For this assignment you will write a Java program using a loop that will play a simple Guess The Number game. Create a new project named GuessANumber and create a new Java class in that project named GuessANumber.java for this assignment. The program will randomly generate an integer between 1 and 200 (including both 1 and 200 as possible choices) and will enter a loop where it will prompt the user for a guess. If the user has guessed the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT