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...
write Java program has two classes ,( using Inheritance ) first class set ( id ,...
write Java program has two classes ,( using Inheritance ) first class set ( id , name ) and method output second class ( id , name , Mark 1 , Mark 2 , Mark 3 ) method total , average , grade , results ( if the student pass or not ) , and output method
Q.We design classes to create objects in java. Write step wise procedure for (a).How these objects...
Q.We design classes to create objects in java. Write step wise procedure for (a).How these objects created in memory? (b). Which area of memory is used for creation of the objects? (c). What is difference between stack and heap memory in java?
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...
Must be using Java Eclipse Please 4. Test program LinkedList.java, and make sure that you understand...
Must be using Java Eclipse Please 4. Test program LinkedList.java, and make sure that you understand each operation in the program. (refer to linkedListApplication.java) 6. (Programming) Use LinkedList as a reference, add the following operations in the class LinkedList; a) Find the average data values of the linked list. b) Find the node with largest key, and then delete the node. (Note, you must return the node, not just the largest key) c) Test ALL operations (Search, Insert, Delete, Append/Remove...
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.
[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter...
[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter five floating point values from the keyboard (warning: you are not allowed to use arrays or sorting methods in this assignment - will result in zero credit if done!). Have the program display the five floating point values along with the minimum and maximum values, and average of the five values that were entered. Your program should be similar to (have outputted values be...
[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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT