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
IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method...
IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method that does the following: Prompt the user to enter a number of inches Read the number of inches entered from the console Convert the inches into an equivalent number of miles, yards, feet, and inches. Output the results to the console. For example, if a user entered 100000 inches, the program would output: 100000 inches is equivalent to: Miles: 1 Yards: 1017 Feet: 2...
Write a Java class called Person. The class should have the following fields: A field for...
Write a Java class called Person. The class should have the following fields: A field for the person’s name. A field for the person’s SSN. A field for the person’s taxable income. A (Boolean) field for the person’s marital status. The Person class should have a getter and setter for each field. The Person class should have a constructor that takes no parameters and sets the fields to the following values: The name field should be set to “unknown”. The...
JAVA Specify, design, and implement a class called PayCalculator. The class should have at least the...
JAVA Specify, design, and implement a class called PayCalculator. The class should have at least the following instance variables: employee’s name reportID: this should be unique. The first reportID must have a value of 1000 and for each new reportID you should increment by 10. hourly wage Include a suitable collection of constructors, mutator methods, accessor methods, and toString method. Also, add methods to perform the following tasks: Compute yearly salary - both the gross pay and net pay Increase...
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.
Using java: Write a class called StringAlternateSorting what it does: 1. ask user for one String...
Using java: Write a class called StringAlternateSorting what it does: 1. ask user for one String (String1) (must be sorted) 2. ask user for second String (String2) (must be sorted) 3. Then prints all the characters of two previous Strings, in such a way that they are sorted (see examples below). 4. consider the possibility that strings are of different sizes, one or both can be empty, etc. 5. strings can contain any kind of characters as long as they...
Java Programming Using the class below, please ), write a static method called parse that parses...
Java Programming Using the class below, please ), write a static method called parse that parses a String for balanced parentheses. we seek only to determine that the symbol ‘{‘ is balanced with ‘}’. parse accepts a single String parameter and returns an int. If parse returns a minus 1, then there are no errors, otherwise, parse should return the position within the String where an error occurred. For example parse(“{3 + {4/2} }”)   would return -1 parse(“{ { 4*X}”)...
in Java language, in most simple algorithm Using a stack class, write a static method called...
in Java language, in most simple algorithm Using a stack class, write a static method called parse that parses a String for balanced parentheses. we seek only to determine that the symbol ‘{‘ is balanced with ‘}’. parse accepts a single String parameter and returns an int. If parse returns a minus 1, then there are no errors, otherwise, parse should return the position within the String where an error occurred. For example parse(“{3 + {4/2} }”)   would return -1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT