Question

In: Computer Science

*****Using Java 1.         There is a class called Wages. It should have one method: calculateWages. This...

*****Using Java

1.         There is a class called Wages. It should have one method: calculateWages. This method accepts from a user (1) an integer hourly rate and (2) an integer total number of hours worked in a week. It calculates and displays the total weekly wage of an employee. The company pays straight time for the first 40 hours worked by an employee and times and a half for all the hours worked in excess of 40. This class should do the above for exactly three employees.

2.         There is the Java application called WagesTest. In its method main, it creates a new Wages object and calls its method, calculateWages.

Please understand the given Java source files and modify them (appropriately) for adding the following features. If you copy and paste the given code to a Notepad file, please make sure that there are no hidden special characters. You can also write your own code from scratch with the following features:

Do the following for exactly three employees:

  1. Ask the user to enter the employee’s name with “Enter employee name: “

You can assume that the user will key in a one-word name, such as Bill. Use the next() method, not the nextLine() method which is complicated and can mess things up.

  1. Receive the employee name keyed in by the human user.

  1. Ask the user to enter whether this employee is (1) salaried or (2) paid by the hour with

“Is this employee (1) salaried or (2) paid by the hour (1 or 2 only): “

  1. Receive the answer (you can assume that the user will key in either 1 or 2).

  1. If this employee is salaried, then:
    • ask for his/he annual salary with “Enter the annual salary amount: “
    • receive the amount (you can assume that the user will key in a positive integer figure)
    • calculate the weekly pay amount by: annual salary / 52
    • display the calculated weekly pay amount with:

“Pay for Employee <employee name received from #2 above> is <the amount calculated here>”

  1. If this employee is paid by the hour, then:
    • ask for integer hourly rate with “Enter integer hourly rate: “
    • receive the hourly rate value (you can assume that the user will key in a positive integer figure)
    • ask for integer hours worked with “Enter integer hours worked: “
    • receive the hours worked figure (you can assume that the user will key in a positive integer figure
    • if hours worked is greater than 40, then for the first 40 hours worked, calculate the normal pay with the hourly rate * 40 and for every hour over 40, calculate the overtime pay with 1.5 times the hourly rate * the extra hours over 40
    • if hours worked is not greater than 40, then calculate the normal pay with the hourly rate * the number of hours worked
    • display the calculated weekly pay amount with:

“Pay for Employee <employee name received from #2 above> is <the amount calculated here>”

Solutions

Expert Solution

1.

import java.util.*;

class Wages // class
{
   private Scanner input = new Scanner(System.in);
  
public void calculateWages()
{
   double wage;
  
   for(int i=1;i<=3;i++)
   {
   System.out.println("Enter hourly rate : ");
   int hourlyRate = input.nextInt();
  
   System.out.println("Enter total number of hours worked in a week : ");
   int hours = input.nextInt();
  
   if(hours <= 40)
   wage = hourlyRate * hours;
   else
   wage = 40*hourlyRate + (hours-40)*hourlyRate *1.5;
   System.out.println("Wage : "+wage);
   }
}
  
}

  
class WagesTest
{
   public static void main (String[] args)
   {
       Wages w = new Wages();
       w.calculateWages();
  

   }
}

2.

import java.util.*;


  
class WagesTest
{
   public static void main (String[] args)
   {
      
       Scanner input1 = new Scanner(System.in);
       String empName;
       double annualSalary,weeklySalary;
      
       for(int i = 1;i<=3;i++)
       {
      
       System.out.println("Enter employees's name : ");
       empName = input1.next();
  

       System.out.println("Is this employee (1) salaried or (2) paid by the hour (1 or 2 only): ");
       int option = input1.nextInt();
      
  
       switch(option)
       {
           case 1: System.out.println("Enter the annual salary amount: ");
                   annualSalary = input1.nextInt();
                   weeklySalary = annualSalary / 52;
                   System.out.println("Pay for Employee "+empName+" is "+ weeklySalary);
                   break;
          
           case 2:
      
                   System.out.println("Enter integer hourly rate: ");
                   int hourlyRate = input1.nextInt();
  
                       System.out.println("Enter total number of hours worked in a week : ");
                   int hours = input1.nextInt();
  
                   if(hours <= 40)
                   weeklySalary = hourlyRate * hours;
                   else
                   weeklySalary = 40*hourlyRate + (hours-40)*hourlyRate *1.5;

                   System.out.println("Pay for Employee "+empName+" is "+weeklySalary);
                   break;
          
           default :
                   System.out.println("Invalid option");
                   break;
       }
      
      
       }


   }
}

Output:

Enter employees's name : Bill
Is this employee (1) salaried or (2) paid by the hour (1 or 2 only): 1
Enter the annual salary amount: 72000
Pay for Employee Bill is 1384.6153846153845
Enter employees's name : Tom
Is this employee (1) salaried or (2) paid by the hour (1 or 2 only): 2
Enter integer hourly rate: 10
Enter total number of hours worked in a week : 41
Pay for Employee Tom is 415.0
Enter employees's name : Smith
Is this employee (1) salaried or (2) paid by the hour (1 or 2 only): 2
Enter integer hourly rate: 12
Enter total number of hours worked in a week : 38
Pay for Employee Smith is 456.0

Do ask if any doubt. Please upvote.


Related Solutions

Assignment 1: Build a simple class called DBTester.java. This class should have only one method, main...
Assignment 1: Build a simple class called DBTester.java. This class should have only one method, main method. In the main method you should read in all of the rows of data from the Instructors Table in the Registration Database, then print out this data. Follow the steps outlined in class. Remember to use try-catch blocks for all database access code. The example in the book does not use Try-catch blocks, but you should
USING JAVA: complete these one method in the BasicBioinformatics class /** * Class BasicBioinformatics contains static...
USING JAVA: complete these one method in the BasicBioinformatics class /** * Class BasicBioinformatics contains static methods for performing common DNA-based operations in * bioinformatics. * * */ public class BasicBioinformatics { /** * Calculates and returns the reverse complement of a DNA sequence. In DNA sequences, 'A' and 'T' * are complements of each other, as are 'C' and 'G'. The reverse complement is formed by * reversing the symbols of a sequence, then taking the complement of each...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named coin and an object of the class Random called r. Coin will have a value of 0 or 1 (corresponding to heads or tails respectively). The constructor should take a single parameter, an int that indicates whether the coin is currently heads (0) or tails (1). There is no need to error check the input. The constructor should initialize the coin instance variable to...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called without instantiating the class and returns a random Date between Jan 1, 2000 and Dec 31, 2010.
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level,...
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level, cottage, etc.) and size. Provide the following methods: A no-arg/default constructor. A constructor that accepts parameters. A constructor that accepts the type of the house and sets the size to 100. All other required methods. An abstract method for calculating heating cost. Come up with another abstract method of your own. Then write 2 subclasses, one for mobile house and one for cottage. Add...
By using Python: a. Make a class called Book. The __init__() method for Book should store...
By using Python: a. Make a class called Book. The __init__() method for Book should store two attributes: a title and an author. Make a method called book_info() that prints these two pieces of information, and a method called book_available() that prints a message indicating that the book is available in the library. b. Create an instance called book1 from your class. Print the two attributes individually, and then call both methods. c. Create three different instances from the class,...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
Java programming. Write a public Java class called DecimalTimer with public method displayTimer, that prints a...
Java programming. Write a public Java class called DecimalTimer with public method displayTimer, that prints a counter and then increments the number of seconds. The counter will start at 00:00 and each time the number of seconds reaches 60, minutes will be incremented. You will not need to implement hours or a sleep function, but if minutes or seconds is less than 10, make sure a leading zero is put to the left of the number. For example, 60 seconds:...
JAVA - Design and implement a class called Flight that represents an airline flight. It should...
JAVA - Design and implement a class called Flight that represents an airline flight. It should contain instance data that represent the airline name, the flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several Flight...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT