1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mademuasel [1]
3 years ago
8

Write a program that demonstrates the class by creating a Payroll object, then asking the user to enter the data for an employee

.
Computers and Technology
1 answer:
AlexFokin [52]3 years ago
8 0

Answer:

import java.util.Scanner;

public class Payroll {

   //set variable field

   private String name;

   private int idNumber;

   private double hourlyRate;

   private int hoursWorked;

   private double grossPay;

   //methods to get values of private class variables

   public String getName()

    {

        return name;

    }

   public int getIdNumber()

   {

      return idNumber;

   }

   public double getHourlyRate()

   {

       return hourlyRate;

   }

   public int getHoursWorked()

   {

       return hoursWorked;

   }

   public double getGrossPay()

   {

      return hoursWorked * hourlyRate;

   }

   //methods to initialize or change the private class values.

   public void setName( String nameGiven)

   {

       name = nameGiven;

   }

   public void setIdNumber(int idNumberGiven)

   {

       idNumber = idNumberGiven;

   }

   public void setHourlyRate(double rateGiven)

   {

       hourlyRate = rateGiven;

   }

   public void setHoursWorked(int hoursGiven)

   {

      hoursWorked = hoursGiven;

   }

   //Constructors

   public Payroll(String nameGiven, int idNumberGiven, double rateGiven, int hoursGiven)

   {

       name = nameGiven;

       idNumber = idNumberGiven;

       hourlyRate = rateGiven;

        hoursWorked = hoursGiven;

   }

 

   public static void main(String[] args)

   {

       double userGrossPay;

       String userEmplName;

       int userIdNum;

       double userRate;

       int userHours;

       Scanner scanner = new Scanner(System.in);

       System.out.print("Enter employee's name:");

       userEmplName = scanner.nextLine();

      System.out.print("Enter employee's ID number:");

       userIdNum = scanner.nextInt();

       System.out.print("Enter hourly rate:");

       userRate = scanner.nextDouble();

       System.out.print("Enter number of hours worked:");

       userHours = scanner.nextInt();

        Payroll payroll1 = new Payroll(userEmplName, userIdNum, userRate, userHours);

 

      payroll1.setName(userEmplName);

       payroll1.setIdNumber(userIdNum);

       payroll1.setHourlyRate(userRate);

       payroll1.setHoursWorked(userHours);

 

       System.out.printf(userEmplName + ", employee number " + userIdNum + ", made $%.2f in gross pay.\n", payroll1.getGrossPay());

}

}

Explanation:

The class "Payroll" is used to hold data of employees to be paid. the main function creates an instance of the class "payroll1", sets the name, id-number, hourly rate, and hours worked by the employee, then prints on screen the details of the payroll1 object.

You might be interested in
Can someone tell me how to get rid of the the orange with blue and orange on the status bar
igor_vitrenko [27]

Answer:

Explanation:

i'm not sure how tho

5 0
3 years ago
Read 2 more answers
Comment if u wanna text me on behance
kow [346]

Answer:

what is behance? :)

Explanation:

4 0
3 years ago
If you sort a portion of an Excel sheet and you get an error message such as #DIV/0, what is a likely cause of the error message
yulyashka [42]
<span>If you sort a portion of an Excel sheet and you get an error message such as #DIV/0, the cause of the error message is (B) one or more cells containing absolute cell references. The possible reason of this error message includes: (1) e</span><span>ntering division formula that divided by zero (0), (2) and that is being used as a reference.</span>
7 0
3 years ago
WILL UPVOTE ALL plz
OverLord2011 [107]
D-ash is the answer.
8 0
3 years ago
What is web based<br> What is local <br> What is mobile in computer
Radda [10]

Answer:

The mobile web refers to browser-based World Wide Web services accessed from handheld mobile devices, such as smartphones or feature phones, or a device. hope this helps :)

Explanation:

6 0
3 years ago
Other questions:
  • true /falseCompression of entries in the term-document matrix can be used to reduce run-time storage and execution-time requirem
    10·1 answer
  • Bit rate is a measure of how many bits of data are transmitted per second. Compared to videos with a higher bit rate, the same v
    13·1 answer
  • A defined set of standards that computers must follow in order to communicate properly is known as a
    13·2 answers
  • For conditional formatting, a formula must be in the form of a(n) _____ test that results in a true or false value. Question 1 o
    8·1 answer
  • Top/bottom rules allows user to apply conditional formatting cells that fall within the top or bottom numbers or percentile. how
    7·1 answer
  • A potential threat to administrators’ ability to manage the correctional system is
    12·1 answer
  • What X coordinate does the center of a game begin at?
    9·1 answer
  • What will be the results from running the following code?
    5·1 answer
  • A _____ is the viewing area for a web page, which is much smaller on a phone than on a traditional desktop.
    7·1 answer
  • While conducting routine maintenance, you discover a network server that needs to
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!