Question

In: Computer Science

Updating the following Java program below, I need to continue to take input for every employee...

Updating the following Java program below, I need to continue to take input for every employee in a company, and display their information until a sentinel value is entered that exits the loop and ends the program

import java.util.Scanner;
public class SalaryCalc
{
double Rpay=0, Opay=0;
void calPay(double hours, double rate)
{
if(hours<=40)
{
Rpay = hours * rate;
Opay = 0;
}
else
{
double Rhr,Ohr;
Rhr = 40;
Ohr = hours-Rhr;
Rpay = Rhr * rate;
Opay = Ohr * (1.5*rate);
}
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String name;
int shift = 0;
Double rate, hours;
System.out.println("Pay Calculator");
System.out.println("Enter Your Name");
name=sc.next();
System.out.println("Enter Your Shift, Enter 0 for Day, Enter1 for Night");
System.out.println("0=Day, 1= Night");
System.out.println("Enter Number of Hours Worked");
hours=sc.nextDouble();
System.out.println("Enter Hourly Pay");
rate=sc.nextDouble();
SalaryCalc c= new SalaryCalc();
c.calPay(hours,rate);
Double Tpay= c.Rpay+ c.Opay;
System.out.println();
System.out.println("Calculate Pay");
System.out.println("Employee Name: "+name);
System.out.println("Employee Regular Pay: "+c.Rpay);
System.out.println("Employee Overtime Pay: "+c.Opay);
System.out.println("Employee Total Pay: "+Tpay);
if(shift==0)
{
System.out.println("Employee PayPeriod is Friday");
}
else
{
System.out.println("Employee PayPeriod is Saturday");
}
}
}

Solutions

Expert Solution

Program screenshots:

Sample Output:

Code to Copy:

import java.util.Scanner;

public class SalaryCalc {
   double Rpay = 0, Opay = 0;

   void calPay(double hours, double rate) {
       if (hours <= 40) {
           Rpay = hours * rate;
           Opay = 0;
       } else {
           double Rhr, Ohr;
           Rhr = 40;
           Ohr = hours - Rhr;
           Rpay = Rhr * rate;
           Opay = Ohr * (1.5 * rate);
       }
   }

   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       String name;
       int shift = 0;
       Double rate, hours;
       System.out.println("Pay Calculator");

       // Declare the variable of string type.
       String ch = "";

       // start the do while loop
       do {

           System.out.println("Enter Your Name");
           name = sc.next();
           System.out.println("Enter Your Shift, Enter 0 for Day, Enter1 for Night");
           System.out.println("0=Day, 1= Night");

           // get the value of shift.
           shift = sc.nextInt();
           System.out.println("Enter Number of Hours Worked");
           hours = sc.nextDouble();
           System.out.println("Enter Hourly Pay");
           rate = sc.nextDouble();
           SalaryCalc c = new SalaryCalc();
           c.calPay(hours, rate);
           Double Tpay = c.Rpay + c.Opay;
           System.out.println();
           System.out.println("Calculate Pay");
           System.out.println("Employee Name: " + name);
           System.out.println("Employee Regular Pay: " + c.Rpay);
           System.out.println("Employee Overtime Pay: " + c.Opay);
           System.out.println("Employee Total Pay: " + Tpay);
          
          
          
          
           if (shift == 0) {
               System.out.println("Employee PayPeriod is Friday");
           } else {
               System.out.println("Employee PayPeriod is Saturday");
           }
          // get the value from the user(sentinel value.)
           System.out.println("Press Y to continue.Other key to exit ");
           ch = sc.next();
           // check the sentinel value.
       } while (ch.equalsIgnoreCase("y"));

   }
}


Related Solutions

I need to update this java program to take input about each employee from a file...
I need to update this java program to take input about each employee from a file and write their information and salary/pay information to a file. use input file payroll.txt Kevin Yang 60 20 Trey Adams 30 15 Rick Johnson 45 10 Cynthia Wheeler 55 11.50 Sarah Davis 24 10 Muhammad Rabish 66 12 Dale Allen 11 18 Andrew Jimenez 80 15 import java.util.Scanner; public class SalaryCalcLoop { double Rpay = 0, Opay = 0; void calPay(double hours, double rate)...
I need to update this java program to take input about each employee from a file...
I need to update this java program to take input about each employee from a file and write their information and salary/pay information to a file. use input file payroll.txt import java.util.Scanner; public class SalaryCalcLoop { double Rpay = 0, Opay = 0; void calPay(double hours, double rate) { if (hours <= 40) { Rpay = hours * rate; Opay = 0; } else { double Rhr, Ohr; Rhr = 40; Ohr = hours - Rhr; Rpay = Rhr *...
In Java, I need a program that will ask a user to input how many tests...
In Java, I need a program that will ask a user to input how many tests they want the average of. For example, It needs to ask the user how many tests would you like the average of? When the user enters the amount of tests they want the average score of, the program needs to give them that many test scores to input. Then with the average, determine what their grade is, if 90-100=A if 80-90 = B etc....
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
Write a program in Java that will take as input two sets A and B, and...
Write a program in Java that will take as input two sets A and B, and returns a list of all functions from A to B.
JAVA JAVA JAVA . I need to convert a string input to int array, for example...
JAVA JAVA JAVA . I need to convert a string input to int array, for example if user enters 12 / 27 / 2020 , I want to store each value in a separate array and add them afterwards.
Write a java program that will take a line of input and go through and print...
Write a java program that will take a line of input and go through and print out that line again with all the word numbers swapped with their corresponding numeric representations (only deal with numbers from one to nine). Sample runs might look like this: Please enter a line of input to process: My four Grandparents had five grandchildren My 4 grandparents had 5 grandchildren without array and methods.
JAVA Take in a user input. if user input is "Leap Year" your program should run...
JAVA Take in a user input. if user input is "Leap Year" your program should run exercise 1 if user input is "word count" your program should run exercise 2 Both exercises should run in separate methods Exercise 1: write a java method to check whether a year(integer) entered by the user is a leap year or not. Exercise 2: Write a java method to count all words in a string.
This question need to be solved using java coading :- I. Input All input data are...
This question need to be solved using java coading :- I. Input All input data are from a file "in.dat". The file contains a sequence of infix form expressions, one per line. The character '$' is an end mark. For example, the following file has four infix form expressions: 1 + 2 * 3 ^ ! ( 4 == 5 ) $ 3 * ( 6 - 4 * 5 + 1) + 2 ^ 2 ^ 3 $ 77...
This question need to be solved using java coading :- I. Input All input data are...
This question need to be solved using java coading :- I. Input All input data are from a file "in.dat". The file contains a sequence of infix form expressions, one per line. The character '$' is an end mark. For example, the following file has four infix form expressions: 1 + 2 * 3 ^ ! ( 4 == 5 ) $ 3 * ( 6 - 4 * 5 + 1) + 2 ^ 2 ^ 3 $ 77...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT