Question

In: Computer Science

SalaryCalculator in Java. The SalaryCalculator class should have instance variables of: an employee's name, reportID that...

SalaryCalculator in Java. The SalaryCalculator class should have instance variables of:

an employee's name, reportID that is unique and increments by 10, and an hourly wage.

There should also be some constructors and mutators, and accessor methods.

Solutions

Expert Solution

class SalaryCalculator {

    private String name;
    private int reportID;
    private double hourlyWage;
    private static int id = 0;

    public SalaryCalculator(String name) {
        this(name, 0);
    }

    public SalaryCalculator(String name, double hourlyWage) {
        this.name = name;
        this.hourlyWage = hourlyWage;
        reportID = id;
        id += 10;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getHourlyWage() {
        return hourlyWage;
    }

    public void setHourlyWage(double hourlyWage) {
        this.hourlyWage = hourlyWage;
    }

    public int getReportID() {
        return reportID;
    }
}

class SalaryCalculatorTest {

    public static void main(String[] args) {
        SalaryCalculator calculator = new SalaryCalculator("Ronaldo");
        calculator.setHourlyWage(10);
        System.out.println("Name: " + calculator.getName());
        System.out.println("Hourly wage: " + calculator.getHourlyWage());
        System.out.println("Report ID: " + calculator.getReportID());
    }
}


Related Solutions

In Java The Order class should have:  Seven instance variables: the order number (an int),...
In Java The Order class should have:  Seven instance variables: the order number (an int), the Customer who made the order, the Restaurant that receives the order, the FoodApp through which the order was placed, a list of food items ordered (stored as an array of FoodItem), the total number of items ordered (an int), and the total price of the order (a double).  A class constant to set the maximum number of items that can be ordered...
(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...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
In java Implement the class Book. It has the following instance variables: name, subject, year, maximumLoanPeriod,...
In java Implement the class Book. It has the following instance variables: name, subject, year, maximumLoanPeriod, and loanPeoriod. The following methods should be included: • Constructor(s), Accessors and Mutators as needed. • public double computeFine() => calculates the fine due on this item The fine is calculated as follows: • If the loanPeriod <= maximumLoanPeriod, there is no fine on the book. • If loanPeriod > maximumLoanPeriod o If the subject of the book is "CS" the fine is 10.00...
You need to make an AngryBear class.(In java) The AngryBear class must have 2 instance variables....
You need to make an AngryBear class.(In java) The AngryBear class must have 2 instance variables. The first instance variable will store the days the bear has been awake. The second instance variable will store the number of teeth for the bear. The AngryBear class will have 1 constructor that takes in values for days awake and number of teeth. The AngryBear class will have one method isAngry(); An AngryBear is angry if it has been awake for more than...
#Write a class called "Burrito". A Burrito should have the #following attributes (instance variables): # #...
#Write a class called "Burrito". A Burrito should have the #following attributes (instance variables): # # - meat # - to_go # - rice # - beans # - extra_meat (default: False) # - guacamole (default: False) # - cheese (default: False) # - pico (default: False) # - corn (default: False) # #The constructor should let any of these attributes be #changed when the object is instantiated. The attributes #with a default value should be optional. Both positional #and...
Java... Design a Payroll class with the following fields: • name: a String containing the employee's...
Java... Design a Payroll class with the following fields: • name: a String containing the employee's name • idNumber: an int representing the employee's ID number • rate: a double containing the employee's hourly pay rate • hours: an int representing the number of hours this employee has worked The class should also have the following methods: • Constructor: takes the employee's name and ID number as arguments • Accessors: allow access to all of the fields of the Payroll...
USE JAVA PLEASE A Phone class has 4 instance variables Model name ("iPhone12","Galaxy") RAM (number of...
USE JAVA PLEASE A Phone class has 4 instance variables Model name ("iPhone12","Galaxy") RAM (number of gigs such as 8 and12) Storage (number of gigs such as 128 and 512) Screen of type class Screen as described below.    A Screen has 3 instance variables: Screen type ("AMOLED", "LCD") Screen size (decimal number such as 6.2 and 10.1) Screen ppi (448, 630, 300)    Q1) Code two class-shell for both classes. The names and types of the instance variables have...
Define a class for the student record. The class should instance variables for Quizzes, Midterm, Final...
Define a class for the student record. The class should instance variables for Quizzes, Midterm, Final and total score for the course and final letter grade. The class should have input and output methods. The input method should not ask for the final numeric grade, nor should it ask for final letter grade. The classes should have methods to compute the overall numeric grade and the final letter grade. These two methods will be void methods that set the appropriate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT