Question

Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and...

Java Programming COMP-228

LAB ASSIGNMENT #1

>> Apply the naming conventions for variables, methods, classes, and packages:

- variable names start with a lowercase character for the first word and uppercase for every other word

- classes start with an uppercase character of every word

- packages use only lowercase characters

- methods start with a lowercase character for the first word and uppercase for every other word Java Programming COMP-228

Exercise #1: [5 marks]

Write a Java application using eclipse as IDE, that implements the following class(es) as per business requirements mentioned below:

Create a CommissionEmployee class (CommissionEmployee.java) that has the following instance variables:

- Employee ID, first name, last name, gross sales ( amount in dollars) and commission rate. Define their data types appropriately.

- Define only getters for employee ID, first name, last name. Ensure the proper ( no negative and null values ) data values entered by implementing data validations.

- Define getter and setter for gross sales and commission rate. Ensure the values for them should never be negative or zero.

- Commission rate should be between 0.1 and 1.0%. Set default value 0.1.

- Class should have defined two overloaded constructors:

o One for initializing all the instance data members/variables

o Second for initializing employee ID, first name, last name

- Define a public method - double earnings() which calculates employee’s commission ( commission rate * gross sales/100)

- Define a public method – String toString() which is used to display the object’s data

Create another BasePlusCommissionEmployee class (BasePlusCommissionEmployee.java) that has the following instance variables:

- Employee ID, First name, last name, base salary, gross sales ( amount in dollars) and commission rate. Define their data types appropriately.

- Define only getters for employee ID, first name, last name and base salary. Ensure the proper ( no negative and null values ) data values by implementing data validations.

- Use default value of 200.00 dollars for base salary for all the employees.

- Define getter and setter for gross sales and commission rate. Ensure the values for them should never be negative or zero.

- Commission rate should be between 0.1 and 1.0%. Set default value 0.1.

- Class should have defined two overloaded constructors:

o One for initializing all the instance data members

o Second for initializing employee ID, first name, last name, base salary only ( if you want to set it more than 200.00 dollars)

- Define a public method - double earnings() which calculates employee’s commission ( commission rate * gross sales/100 + base salary )

- Define a public method – String toString() which is used to display the object’s data

Create a HourlyEmployee class (HourlyEmployee.java) that has the following instance variables:

- Employee ID, first name, last name, total number of hours worked per week, and hourly rate ( amount in dollars). Define their data types appropriately.

- Define only getters for employee ID, first name, last name. Ensure the proper (no negative and null values ) data values by implementing data validations.

Java Programming COMP-228

- Define getters and setters for number of hours worked per week and hourly rate. Ensure the values for them should never be negative or zero.

- Hourly rate should be minimum 14.00 dollars per hour.

- Class should have defined two overloaded constructors:

o One for initializing all the instance data members/variables

o Second for initializing employee ID, first name, last name

- Define a public method - double earnings() which calculates employee’s commission (number of hours worked per week * commission rate)

- Define a public method – String toString() which is used to display the object’s data

Create a driver class EmployeeTest (EmployeeTest.java) which tests above classes by at least creating one object each of CommissionEmployee, BasePlusCommissionEmployee and HourlyEmployee classes.

Homework Answers

Answer #1

Please find the answer below, have defined all the details in the comments. Code is developed as per the instructions are given in the question.

CommissionEmployee.java
//CommissionEmployee.java class
public class CommissionEmployee {
    //private date members of the class
    private int employeeId;
    private String firstName;
    private String lastName;
    private double grossSales;
    //default value for the commission rate to 0.1
    private double commissionRate = 0.1;

    //getter methods
    public int getEmployeeId() {
        return employeeId;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    //getter and setter for the grossSales and commissionRate
    public double getGrossSales() {
        return grossSales;
    }

    public void setGrossSales(double grossSales) {
        if(grossSales > 0) {
            this.grossSales = grossSales;
        }
    }

    public double getCommissionRate() {
        return commissionRate;
    }

    public void setCommissionRate(double commissionRate) {
        if(commissionRate > 0 && (commissionRate >= 0.1 && commissionRate<=1.0)) {
            this.commissionRate = commissionRate;
        }
    }

    //constructor 1
    public CommissionEmployee(int employeeId, String firstName, String lastName, double grossSales, double commissionRate) {
        if(employeeId > 0)
            this.employeeId = employeeId;
        this.firstName = firstName;
        this.lastName = lastName;
        if(grossSales > 0)
            this.grossSales = grossSales;
        if(commissionRate > 0 && (commissionRate >= 0.1 && commissionRate<=1.0))
            this.commissionRate = commissionRate;
    }

    //constructor 2
    public CommissionEmployee(int employeeId, String firstName, String lastName) {
        if(employeeId > 0)
            this.employeeId = employeeId;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    //earnings to calculate the earning of the employee
    public double earnings(){
        double commission = 0;
        commission = (this.commissionRate*this.grossSales)/100.0;
        return commission;
    }

    //to string method to print the details
    @Override
    public String toString() {
        return "CommissionEmployee{" +
                "employeeId=" + employeeId +
                ", firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", grossSales=" + grossSales +
                ", commissionRate=" + commissionRate +
                '}';
    }
}
BasePlusCommissionEmployee.java
public class BasePlusCommissionEmployee {
    //private date members of the class
    private int employeeId;
    private String firstName;
    private String lastName;
    //default value for the base salary
    private double baseSalary = 200.00;
    private double grossSales;
    //default value for the commission rate to 0.1
    private double commissionRate = 0.1;

    //getters
    public int getEmployeeId() {
        return employeeId;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public double getBaseSalary() {
        return baseSalary;
    }

    //getter and setter for the grossSales and commissionRate
    public double getGrossSales() {
        return grossSales;
    }

    public void setGrossSales(double grossSales) {
        if(grossSales > 0) {
            this.grossSales = grossSales;
        }
    }

    public double getCommissionRate() {
        return commissionRate;
    }

    public void setCommissionRate(double commissionRate) {
        if(commissionRate > 0 && (commissionRate >= 0.1 && commissionRate<=1.0)) {
            this.commissionRate = commissionRate;
        }
    }

    //constructor 1
    public BasePlusCommissionEmployee(int employeeId, String firstName, String lastName, double baseSalary, double grossSales, double commissionRate) {
        if(employeeId > 0)
            this.employeeId = employeeId;
        this.firstName = firstName;
        this.lastName = lastName;
        if(baseSalary > 0)
            this.baseSalary = baseSalary;
        if(grossSales > 0)
            this.grossSales = grossSales;
        if(commissionRate > 0 && (commissionRate >= 0.1 && commissionRate<=1.0))
            this.commissionRate = commissionRate;
    }

    //constructor 2
    public BasePlusCommissionEmployee(int employeeId, String firstName, String lastName, double baseSalary) {
        if(employeeId > 0)
            this.employeeId = employeeId;
        this.firstName = firstName;
        this.lastName = lastName;
        if(baseSalary > 200)
            this.baseSalary = baseSalary;
    }

    //earnings to calculate employee's earnings
    public double earnings(){
        double commision = ((this.commissionRate * this.grossSales)/100.0) + this.baseSalary;
        return commision;
    }

    //tostring the print the object details
    @Override
    public String toString() {
        return "BasePlusCommissionEmployee{" +
                "employeeId=" + employeeId +
                ", firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", baseSalary=" + baseSalary +
                ", grossSales=" + grossSales +
                ", commissionRate=" + commissionRate +
                '}';
    }
}
HourlyEmployee.java
public class HourlyEmployee {
    //private date members of the class
    private int employeeId;
    private String firstName;
    private String lastName;
    private double totalHoursWroked;
    //default value for the hourly rate
    private double hourlyRate = 14.00;


    //getters
    public int getEmployeeId() {
        return employeeId;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    //getters and setters

    public double getTotalHoursWroked() {
        return totalHoursWroked;
    }

    public void setTotalHoursWroked(double totalHoursWroked) {
        if(totalHoursWroked > 0)
            this.totalHoursWroked = totalHoursWroked;
    }

    public double getHourlyRate() {
        return hourlyRate;
    }

    public void setHourlyRate(double hourlyRate) {
        if(hourlyRate > 0)
            this.hourlyRate = hourlyRate;
    }

    //constructor 1
    public HourlyEmployee(int employeeId, String firstName, String lastName, double totalHoursWroked, double hourlyRate) {
        if(employeeId > 0)
            this.employeeId = employeeId;
        this.firstName = firstName;
        this.lastName = lastName;
        if(totalHoursWroked > 0)
            this.totalHoursWroked = totalHoursWroked;
        if(hourlyRate > 0)
            this.hourlyRate = hourlyRate;
    }

    //constructor 2
    public HourlyEmployee(int employeeId, String firstName, String lastName) {
        if(employeeId > 0)
            this.employeeId = employeeId;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    //calculate the employee's earnings
    public double earnings(){
        double commision  = (this.totalHoursWroked * this.hourlyRate);
        return commision;
    }

    //print the object details
    @Override
    public String toString() {
        return "HourlyEmployee{" +
                "employeeId=" + employeeId +
                ", firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", totalHoursWroked=" + totalHoursWroked +
                ", hourlyRate=" + hourlyRate +
                '}';
    }
}
EmployeeTest.java
public class EmployeeTest {
    public static void main(String[] args) {
        CommissionEmployee cme = new CommissionEmployee(1,"John","Jacob",100000,0.5);
        System.out.println("Commission Employee Details: ");
        System.out.println(cme);
        System.out.println("Commission Employee Earnings: " + cme.earnings());
        System.out.println();

        BasePlusCommissionEmployee bcme = new BasePlusCommissionEmployee(2,"Any","Kay",500,100000,0.5);
        System.out.println("Base plus Commission Employee Details: ");
        System.out.println(bcme);
        System.out.println("Base plus Commission Employee Earnings: " + bcme.earnings());
        System.out.println();

        HourlyEmployee he = new HourlyEmployee(3,"Neil","Smith",50,20);
        System.out.println("Hourly Employee Details: ");
        System.out.println(he);
        System.out.println("Hourly Employee Earnings: " + he.earnings());
    }
}

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String),...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String), Monthly Salary (double)). Create a constructor that initializes these variables. Define set and get methods for each variable. If the monthly salary is not positive, do not set the salary. Create a separate test class called EmployeeTest that will use the Employee class. By running this class, create two employees (Employee object) and print the annual salary of each employee (object). Then set the...
Use a few sentences to describe the problem given below . Also, Identify the nouns and...
Use a few sentences to describe the problem given below . Also, Identify the nouns and verbs used in the below project descriptions.  Identified nouns, list the ones that are necessary to define variables in your program. For each variable, specify its name, data type, and what information it is used to store. Write the pseudo code algorithm (i.e. algorithm steps) to solve this problem. (For the base salaries and commission rates use constants instead to keep these values. Use the...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do depending upon what the user enters, please refer to the examples below to use to test your program. Run your final program one time for each scenario to make sure that you get the expected output. Be sure to format the output of your program so that it follows what is included in the examples. Remember, in all examples bold items are entered by...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately difficult problem. Program Description: This project will alter the EmployeeManager to add a search feature, allowing the user to find an Employee by a substring of their name. This will be done by implementing the Rabin-Karp algorithm. A total of seven classes are required. Employee (From previous assignment) HourlyEmployee (From previous assignment) SalaryEmployee (From previous assignment) CommissionEmployee (From previous assignment) EmployeeManager (Altered from previous...
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation....
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation. case:    W17400 APIGEE: PEOPLE MANAGEMENT PRACTICES AND THE CHALLENGE OF GROWTH Ranjeet Nambudiri, S. Ramnarayan, and Catherine Xavier wrote this case solely to provide material for class discussion. The authors do not intend to illustrate either effective or ineffective handling of a managerial situation. The authors may have disguised certain names and other identifying information to protect confidentiality. This publication may not be...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...