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
postnew [5]
3 years ago
9

In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: Str

ing id: String hours: int rate: double private members . You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception should be thrown. An employee id should have the form LNN. If that form is not received, an exception should be thrown. An employee's hours should neither be negative nor greater than 84. An exception should be thrown otherwise. An employee's pay rate should neither be negative nor greater than 25.00. An exception should be thrown otherwise. Demonstrate this class in a program (separate class or in the same class). The exception messages should be appropriate to the specific exception that has occurred. Create a package payroll for the project.

Computers and Technology
1 answer:
wlad13 [49]3 years ago
5 0

Answer:

Here is the PayRoll class:

// PayRoll.java

package payroll;  // creates payroll package for project

public class Payroll {   //class definition

  private String name;   //private String type member variable to store name

  private String id;  //private String type member variable to store id

  private int hours;  //private int type member variable to store work hours

  private double rate;    //private double type member variable to store payrate of the employee

  public Payroll()    {  //no argument constructor of PayRoll

      name = "";   //initialize name field

      id = "";   //initialize id field

      hours = 0;  //initialize hours field

      rate = 0.0;    }  //  initialize rate field

  public Payroll(String NAME, String ID, int HOURS, double RATE)    { //parameterized constructor

      setName(NAME);  //sets name value

      setId(ID); //sets id value

      setHours(HOURS);  //sets hours value

      setRate(RATE);    }  //sets rate value

  public void setName(String NAME)    {  //mutator method to set name

      if(NAME.equals(""))        {  //if name field is empty

          throw new IllegalArgumentException("An employee name should not be empty.");        }     //throws exception

      name = NAME;    }  

  public void setId(String ID)    {        //mutator method to set id

      if(ID.length() != 3 || !Character.isLetter(ID.charAt(0))|| !Character.isDigit(ID.charAt(1)) || !Character.isDigit(ID.charAt(2)))        {  //if statement checks if the length of the id is not 3, or first character of id is not a letter, or second or third character of id is not a digit

          throw new IllegalArgumentException("An employee id should have the form LNN.");        }        //throws exception

      id = ID;    }    

  public void setHours(int HOURS)    {  //mutator method to set hours

      if(HOURS < 0 || HOURS > 84)        { //checks if working hours are less than 0 or greater than 84

          throw new IllegalArgumentException("An employee's hours should neither be negative nor greater than 84");        }    //throws exception    

      hours = HOURS;    }  

  public void setRate(double RATE)    {    //mutator method to set rate

      if(RATE < 0 || RATE > 25.00)        {  //checks if pay rate is less than 0 or greater than 25.00

          throw new IllegalArgumentException("An employee's pay rate should neither be negative nor greater than 25.00");        }         //throws exception    

      rate = RATE;    }    

  public String getName()    {  //accessor method to get value of name

      return name;    }   //returns the current value of name

  public String getId()    { //accessor method to get value of id

      return id;    }  //returns the current value of id

  public int getHours()    {  //accessor method to get value of hours

      return hours;    }    //returns the current value of hours

   public double getRate()    {  //accessor method to get value of rate

      return rate;    }  } //returns the current value of rate

Explanation:

Here is the Main() class:

import java.util.Scanner;  //to accept input from user

public class Main {  //Main class definition

  public static void main(String[] args)   {//start of main() function

      Payroll pay = new Payroll();  //creates object i.e. pay of PayRoll class

      Scanner sc = new Scanner(System.in);  //creates Scanner class object

      String name,id; //declare variables to hold name and id

      int hour;  //declare variable to store hour

      double rate; //declare variable to store pay rate

      System.out.print("Enter the employee's name: "); //prompts user to enter employee name

      name = sc.nextLine();  //reads input value of name

      pay.setName(name);  //use pay object to access mutator method to set name to input name value

      System.out.print("Enter employee's id (LNN form): "); //prompts user to enter employee id

      id = sc.nextLine();  //reads input value of id

      pay.setId(id);  //use pay object to access mutator method to set id to input id

      System.out.print("Enter the employee's working hours: "); //prompts user to enter employee hours

      hour = sc.nextInt();  //reads input value of hour

      pay.setHours(hour);  // set input hours

      System.out.print("Enter the employee's pay rate: "); //prompts user to enter employee pay rate

      rate = sc.nextInt(); //reads input value of rate

      pay.setRate(rate);  // set pay rate

      System.out.println("Employee Data: \n");  //displays the employee data

      System.out.println("Employee's Name: " + pay.getName());  //calls getName accessor method to get current value of name field and display it

      System.out.println("Employee's ID: " + pay.getId());  //calls getId accessor method to get current value of id field and displays it

      System.out.println("Employee's Hours: " + pay.getHours());  //calls getHours accessor method to get current value of hours field and displays it

      System.out.println("Employee's Pay Rate: " + pay.getRate()); //calls getRate accessor method to get current value of rate field and displays it

  }

}

Here IllegalArgumentException is thrown which is used to show that a method is passed an illegal argument.

The screenshot of program and its output is attached.

You might be interested in
Match the installation type to its description.
MariettaO [177]

Answer:

Following are the types of installation matched to its respective definitions.

<h3>Upgrade installation:</h3>

What you do when you have a computer with an existing operating system that needs to be upgraded.

This means that while working on a window when you get attracted by the update introduced recently and you upgrade your window accordingly.

For example: Updating a window from 8 to 10 or desired features.

<h3>Multiple boot installation:</h3>

What you do when you have several operating systems on one computer.

In this type of installation, a computer has different windows for different accounts. You can boot to the desired installed window by switching account.

<h3>Clean installation:</h3>

What you do on a brand new computer that has never been set up before and does not have an operating system on it yet.

It can be defined as the installation of window done very first time on to the computer. Sometimes when the window gets deleted due to virus or any other factor, the installation at that time will also be termed as Clean Installation.

<h2>I hope it will help you!</h2>
5 0
3 years ago
Match the steps with the actions that are involved when an internal host with IP address 192.168.10.10 attempts to send a packet
Anna35 [415]

Answer:

Following are the steps with actions that are involved in required to perform a packet transfer.

Explanation:

  • Step 1: The host sends a connection request to server which is at IP address 209.165.200.254
  • Step 2: R1 check the configuration of NAT to inquire weather the packet should be translated or not.
  • Step 3: If there is no entry found for translation of given IP address, It is assumed that the IP address 192.168.10.10  will be translated already.
  • Step 4: R1 selects a global address  from the dynamic address pool that is available to it.
  • Step 5: R1 replaces the given IP address 192.168.10.10  with the translated inside global address.

i hope it will help you!

5 0
3 years ago
What is a flowchart​
serious [3.7K]

a diagram of the sequence of movements or actions of people or things involved in a complex system or activity.

4 0
3 years ago
What does % find on edhesive??
statuscvo [17]

Answer:

Explanation: What is that word you typed?

3 0
3 years ago
PLEASE HELP ON THESE 3!! ILL GIVE A BRAINLIEST IF ITS CORRECT!!
Travka [436]
Not entirely sure about 1; I believe it's D. 2 is C, and 3 is A.
5 0
4 years ago
Other questions:
  • What are some good editing software apps for pc?
    11·1 answer
  • Does anyone have any social media message me
    14·1 answer
  • Which key is used in word processors to create indentations?
    13·2 answers
  • __________ is a collection of formatting options—such as a frame, a rounded shape, and a shadow—that changes a picture’s overall
    5·1 answer
  • How do you activate the Formula AutoComplete function of Excel 2016?
    15·2 answers
  • Why are ethics important in PR?
    8·1 answer
  • Consider the class ScopeTest defined this way:
    15·1 answer
  • How many ways do advertisers determine target audiences ??????
    15·1 answer
  • A garments manufacturing company buys various types of natural and synthetic materials to produce clothes. Which material is a s
    6·2 answers
  • Select three advantages of cloud computing.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!