Question

In: Computer Science

Previous info: Cost Is No Object is a car rental service that specializes in lending antique...

Previous info: Cost Is No Object is a car rental service that specializes in lending antique and luxury cars to clients on a short-term basis. A typical customer might rent a vintage convertible to transport out-of-town clients to a business meeting, or rent a luxury car to transport a wedding party. The service currently has three employees and ten vehicles that it rents.

Case Projects CH.4 Case: Cost Is No Object

In earlier chapters, you developed classes needed for Cost Is No Object—a car rental service that specializes in lending antique and luxury cars to clients on a short-term basis. The rental service produces computerized paychecks for its employees every week. Write a program that gets data for each of the following:  

An employee ID number

A first name

  A last name

A street address

A zip code

An hourly pay rate

Number of hours worked this week

An insurance plan code

Create an application that prompts the user for employee data; the application continues to accept data for new employees until the user enters 0 for an ID number to quit. While the ID number is not zero, prompt the user for a value for each field in turn. Any time the user enters an invalid value, continue to reprompt the user for the same data. Continue with the next data item only when the previous item is valid, as follows:

An employee ID must be between 100 and 999 inclusive.

A zip code must not be greater than 99999.

An hourly pay rate must be between $6.00 and $25.00 inclusive.

The number of hours worked in a week cannot be negative or more than 70.

An insurance plan code must be 1 or 2.

When all the needed data has been entered correctly for an employee, display a copy of all the data fields for the employee as well as the following:

Gross pay, calculated as hours worked times pay rate

Income tax, which is calculated as 15% of the gross pay if the gross pay is $400 or less; otherwise, it is 20% of the gross pay

An insurance premium, which is $60 for insurance plan code 1 and $100 for insurance plan code 2

Net pay, which is calculated as gross pay minus income tax, minus insurance premium; if the net pay is negative (the employee did not earn enough to cover the tax and insurance), then the net pay should be $0

Solutions

Expert Solution

TWO CLASSES SO TO KEEP CODE CLEAN AND IN OBJECT ORIENTED APPROACH

EmployeeMain.java class

import java.util.Scanner;

public class EmployeeMain {

    private static double grossPay;
    private static double incomeTax;
    private static double insurancePre;
    private static double netPay;

    public static void main(String[] args ){

        //variable initialization
        String firstName;
        String lastName ;
        String address;
        int zipCode;
        double payRate;
        int numberOfHours;
        int planCode;
        int employeeID;

        EmployeeX employeeX = new EmployeeX();
        Scanner scanner = new Scanner(System.in);
        while ( scanner.hasNext() ){
            employeeID = scanner.nextInt();

            if( employeeID != 0 ){
                
                //checks for valid ID
                while (!( employeeID <= 999 && employeeID >= 100 )){
                    System.out.println(" Enter valid ID ");
                    employeeID = scanner.nextInt();
                }
                employeeX.setEmployeeID(employeeID);

                scanner.nextLine();
                
                //take the name and address
                System.out.println(" Enter the first Name ");
                firstName = scanner.nextLine();
                employeeX.setFirstName(firstName);

                System.out.println(" Enter the last Name ");
                lastName = scanner.nextLine();
                employeeX.setLastName(lastName);

                System.out.println(" Enter the address ");
                address = scanner.nextLine();
                employeeX.setAddress(address);

                //takes the valid zipcode
                do{
                    System.out.println(" Enter the ZipCode ");
                    zipCode = scanner.nextInt();
                    employeeX.setZipcode(zipCode);
                }while (!( zipCode < 99999 ));

                //take the valid pay rate
                do{
                    System.out.println(" Enter the Pay Rate ");
                    payRate = scanner.nextDouble();
                    employeeX.setPayRate(payRate);
                }while (!( payRate <= 25.00 && payRate >= 6.00 ));

                //takes the valid number of hour of work
                do{
                    System.out.println(" Enter the number of Hours of work ");
                    numberOfHours = scanner.nextInt();
                    employeeX.setNumberOfHours(numberOfHours);
                }while(!( numberOfHours >= 0 && numberOfHours <= 70 ));

                //takes the valid plan Code
                do{
                    System.out.println(" Enter the plan Code ");
                    planCode = scanner.nextInt();
                    employeeX.setPlanCode(planCode);
                }while( !( planCode == 1 || planCode == 2 ));


                //calculates the grossPay
                grossPay = numberOfHours*payRate;
                
                //calculates the income Tax
                if( grossPay <= 400 ){
                    incomeTax = 0.15*grossPay;
                }
                else {
                    incomeTax = 0.20*grossPay;
                }

                //checks for insurance Premium according to planCode
                if( employeeX.getPlanCode() == 1 ){
                    insurancePre = 100;
                }
                else {
                    insurancePre = 60;
                }

                //calculates the netPay
                netPay = grossPay-incomeTax-insurancePre;
                if( netPay < 0 ){
                    netPay = 0;
                }

                print();

            }
            else{
                break;
            }
        }
    }

    //Prints the data for the user
    public static void print(){
        EmployeeX employeeX = new EmployeeX();
        System.out.println( " Name = " + employeeX.getFirstName() + " " + employeeX.getLastName() + "\n Address = " + employeeX.getAddress() + "\n ZipCode = " + employeeX.getZipcode() +
                "\n Employee ID Number = " + employeeX.getEmployeeID() + "\n Pay Rate = $" + employeeX.getPayRate() +
                "\n Number Of Hours Worked = "+ employeeX.getNumberOfHours() + "\n Plan Code = " + employeeX.getPlanCode() );

        System.out.println( " GrossPay = " + grossPay + "\n Net Pay = " + netPay );
    }
}

EmployeeX.java class

public class EmployeeX {

    //variable initialization
    private static int employeeID;
    private static int zipcode;
    private static double payRate;
    private static int numberOfHours;
    private static int planCode;
    private static String firstName;
    private static String lastName;
    private static String address;

    //public getters and setters
    public static int getEmployeeID() {
        return employeeID;
    }

    public static void setEmployeeID(int employeeID) {
        EmployeeX.employeeID = employeeID;
    }

    public static int getZipcode() {
        return zipcode;
    }

    public static void setZipcode(int zipcode) {
        EmployeeX.zipcode = zipcode;
    }

    public static double getPayRate() {
        return payRate;
    }

    public static void setPayRate(double payRate) {
        EmployeeX.payRate = payRate;
    }

    public static int getNumberOfHours() {
        return numberOfHours;
    }

    public static void setNumberOfHours(int numberOfHours) {
        EmployeeX.numberOfHours = numberOfHours;
    }

    public static int getPlanCode() {
        return planCode;
    }

    public static void setPlanCode(int planCode) {
        EmployeeX.planCode = planCode;
    }

    public static String getFirstName() {
        return firstName;
    }

    public static void setFirstName(String firstName) {
        EmployeeX.firstName = firstName;
    }

    public static String getLastName() {
        return lastName;
    }

    public static void setLastName(String lastName) {
        EmployeeX.lastName = lastName;
    }

    public static String getAddress() {
        return address;
    }

    public static void setAddress(String address) {
        EmployeeX.address = address;
    }
}

Related Solutions

Creation of an app for a car rental and swap service by four people. Write a...
Creation of an app for a car rental and swap service by four people. Write a operation plan for 5 years. Include answers to the following questions: 1. How will we make or deliver the product or service? 2. What are our distribution channels? 3. Locations, equipment needs. 4. Labour’s, contractor’s requirement. 5. Is there a ‘pay as you go’ option to gradually ramp up production and/or distribution? (Make it in a table with time deadlines)
Startup of an online car rental and swap service by four people. Write a Financial plan...
Startup of an online car rental and swap service by four people. Write a Financial plan for 5 years Include: Sales Forecast Income Statement Cash Flow Statement
The following data represent the daily hotel cost and rental car cost for 20 U.S cities...
The following data represent the daily hotel cost and rental car cost for 20 U.S cities during a week in October 2003 CITY HOTEL CARS San Francisco               205               47 Los Angeles               179               41 Seattle                   185               49 Phoenix               210               38 Denver                   128               32 Dallas                   145  ...
The following data represent the daily rental cost for a compact automobile charged by two car...
The following data represent the daily rental cost for a compact automobile charged by two car rental companies, Thrifty and Hertz, in 10 randomly selected major U.S. cities. Test whether Thrifty is less expensive than Hertz at the α = 0.1 level of significance. City Thrifty Hertz Chicago 21.81 18.99 Los Angeles 29.89 48.99 Houston 17.90 19.99 Orlando 27.98 35.99 Boston 24.61 25.60 Seattle 21.96 22.99 Pittsburgh 20.90 19.99 Phoenix 47.75 36.99 New Orleans 33.81 26.99 Minneapolis 33.49 20.99 Conditions:...
On February 15, 2018, Leo purchased and placed in service a new car that cost $54,600....
On February 15, 2018, Leo purchased and placed in service a new car that cost $54,600. The business use percentage for the car is always 100%. He does not take the additional first-year depreciation or any § 179. If required, round your answers to the nearest dollar. Click here to access the depreciation table of the textbook. Click here to access the limits for certain automobiles. a. What MACRS convention applies to the new car? Half-year b. Is the automobile...
On June 5, 2016, Leo purchased and placed in service a new car that cost $20,000....
On June 5, 2016, Leo purchased and placed in service a new car that cost $20,000. The business use percentage for the car is always 100%. Leo claims any available additional first-year depreciation but does not claim any expense under § 179. a. What MACRS convention applies to the new car? b. Is the automobile considered "listed property"? c. Leo's cost recovery deduction in 2016 is ________ and for 2017 is
Jose Ruiz manages a car dealer’s service department. His department is organized as a cost center....
Jose Ruiz manages a car dealer’s service department. His department is organized as a cost center. Costs for a recent quarter are shown below. Cost of parts $ 22,400 Mechanics’ wages 14,300 Manager’s salary 8,000 Building depreciation (allocated) 4,500 Shop supplies 1,200 Utilities (allocated) 800 Administrative costs (allocated) 2,200 Calculate the total costs that would appear on a responsibility accounting report for the service department.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT