Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an abstract Employee business class with these private instance variables: Employee number: Last name: First name: Email address: Social security number: 1000 9999 numeric

Create an abstract Employee business class with these private instance variables: Employee number: Last name: First name: Email address: Social security number: 1000 9999 numeric present present present 111111111 999999999 numeric Include two constructors, an empty constructor, and one that accepts all parameters, and a get and a set method for each of the instance variables. Include in this abstract class an abstract method called calcPay. The abstract method should accept a double parameter and return a double. You will also need to override the toString() method that will displays all the above fields in a formatted version (make it look nice). Create two subclasses that extend Employee, one for hourly employee, and one for salary employee. Both subclasses should override the abstract method in Employee. Hourly subclass: The hourly subclass should contain an instance variable for number of hours worked, two constructors that call the super class, and a get and set method for the instance variable. Hourly rate should be a constant that cannot be changed and set at 15.75. The calcPay method should accept the number of hours worked as the parameter, and calculate an hourly employees pay by multiplying the number of hours worked by the hourly rate. Salary subclass: The salary subclass should contain an instance variable for yearly salary, two constructors that call the super class, and a get and set method for that instance variable. The calcPay method should accept a yearly salary as the parameter, and calculate a monthly salary by dividing the yearly salary by twelve months. The presentation class should ask for the employee number, last name, first name, email address and social security number. The presentation classs main method should consist almost entirely of method calls. Error checking should be done on all user-entered fields using a Validation class. Those values should be passed to the Employee class. The application class should also ask if the employee is hourly or salary. Based on that answer; determine which calcPay method to call in order to calculate pay. If the employee is hourly, the application should prompt the user for the number of hours worked. That value should be passed to the hourly subclass by calling the setmethod. If the employee is salary, the application should prompt the user for a yearly salary. That value should be passed to the salary subclass by calling the set method. The application class should display all of the users information by calling the toString() method along with their formatted pay by calling the appropriate methods in the business classes. The user should be prompted as to whether they would like to calculate pay for another employee. If the answer is Y in either upper or lower case, the application should start again at the beginning.

employee.java:

package business;

import presentation.Java03;

public class Employee extends Java03

{

//Setting names for the presentation class

private int empNumber;

private String lastName;

private String firstName;

private String email;

private int ssNumber;

private int hoursWorked;

private double hourlyRate = 15.75;

private double totalPay = 0;

//assigning preliminary values

public void employee()

{

empNumber = 0;

lastName = "";

firstName = "";

email = "";

ssNumber = 0;

}

//building constructor

public void employee(int empNumber, String lastName, String firstName, String email, int ssNumber)

{

this.empNumber = empNumber;

this.lastName = lastName;

this.firstName = firstName;

this.email = email;

this.ssNumber = ssNumber;

this.hoursWorked = hoursWorked;

}

//setting getters and setters

public int getEmpNumber() {

return empNumber;

}

//*****************************************

public void setEmpNumber(int empNumber) {

this.empNumber = empNumber;

}

//*****************************************

public String getLastName() {

return lastName;

}

//*****************************************

public void setLastName(String lastName) {

this.lastName = lastName;

}

//*****************************************

public String getFirstName() {

return firstName;

}

//*****************************************

public void setFirstName(String firstName) {

this.firstName = firstName;

}

//*****************************************

public String getEmail() {

return email;

}

//*****************************************

public void setEmail(String email) {

this.email = email;

}

//*****************************************

public int getSsNumber() {

return ssNumber;

}

//*****************************************

public void setSsNumber(int ssNumber) {

this.ssNumber = ssNumber;

}

//*****************************************

public int getHoursWorked() {

return hoursWorked;

}

//*****************************************

public void setHoursWorked(int hoursWorked) {

this.hoursWorked = hoursWorked;

}

//taking the hourly rate and multiplying it by the time worked to get total pay

public double totalPayMethod()

{

totalPay = hourlyRate * hoursWorked;

return totalPay;

}

//returning the information to the presentation class

public String toString()

{

return "Employee Number: " + empNumber + " " +

"Last Name: " + lastName + " " +

"First Name: " + firstName + " "+

"Social Security Number: " + ssNumber + " " +

"total Pay: " + totalPay + " ";

}

}

SalaryEmployee.java:

package business;

import presentation.Java03;

public class SalaryEmployee extends Java03{

//Setting names for the presentation class

private int empNumber;

private String lastName;

private String firstName;

private String email;

private int ssNumber;

private double salary;

private double totalPay;

//assigning preliminary values

public void employee()

{

empNumber = 0;

lastName = "";

firstName = "";

email = "";

ssNumber = 0;

totalPay = 0;

salary = 0;

}

//building constructor

public void salaryEmployee(int empNumber, String lastName, String firstName, String email, int ssNumber, double salary, double totalPay)

{

this.empNumber = empNumber;

this.lastName = lastName;

this.firstName = firstName;

this.email = email;

this.ssNumber = ssNumber;

this.salary = salary;

this.totalPay = totalPay;

}

//building getters and setters

public int getEmpNumber() {

return empNumber;

}

//**********************************************

public void setEmpNumber(int empNumber) {

this.empNumber = empNumber;

}

//**********************************************

public String getLastName() {

return lastName;

}

//**********************************************

public void setLastName(String lastName) {

this.lastName = lastName;

}

//**********************************************

public String getFirstName() {

return firstName;

}

//**********************************************

public void setFirstName(String firstName) {

this.firstName = firstName;

}

//**********************************************

public String getEmail() {

return email;

}

//**********************************************

public void setEmail(String email) {

this.email = email;

}

//**********************************************

public int getSsNumber() {

return ssNumber;

}

//**********************************************

public void setSsNumber(int ssNumber) {

this.ssNumber = ssNumber;

}

//**********************************************

public double getSalary() {

return salary;

}

//**********************************************

public void setSalary() {

this.salary = salary;

}

//**********************************************

public double getTotalPay() {

return totalPay;

}

//**********************************************

public void setTotalPay() {

this.totalPay = totalPay;

}

//taking salary and dividing it by 12 months to see what the monthly pay was

public double totalPayMethod()

{

totalPay = salary / 12;

return totalPay;

}

//Sending the information back to the presentation class

public String toString()

{

return "Employee Number: " + empNumber + " " +

"Last Name: " + lastName + " " +

"First Name: " + firstName + " "+

"Social Security Number: " + ssNumber + " " +

"total Pay: " + totalPay + " ";

}

}

java03:

package presentation;

import java.util.Scanner;

public abstract class Java03 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

//having the user input the information into the calculator and then asking at the end if they would like to continue

do

{

String answer = "";

System.out.println("Welcome to the Employee Pay Rate Calculator");

System.out.print("Is the employee on Salary?");

answer = sc.nextLine();

boolean errorCheck = false;

if (answer.equalsIgnoreCase("y")) {

//setting variables for Salary Employee

String empNum;

String lastName;

String firstName;

String email;

String ssNumber;

//Getting Employee number and ensuring its an integer and within range of 1000 and 9999 and is numerical

do

{

int min = 1000;

int max = 9999;

System.out.print("Please enter the Employee Number");

empNum = sc.nextLine();

errorCheck = Validation.isInteger(empNum, "Employee Number") && Validation.isWithinRangeInteger(empNum, min, max, "Employee Number");

}while(!errorCheck);

int empNumInt = Integer.parseInt(empNum);

//Getting Employee's last name and ensuring the string is there

do

{

System.out.print("Please enter the Employee's Last Name");

lastName = sc.nextLine();

errorCheck = Validation.isStringPresent(lastName, "Last Name");

}while(!errorCheck);

//Getting Employee's first Name and ensuring the string is there

do

{

System.out.print("Please enter the Employee's First Name");

firstName = sc.nextLine();

errorCheck = Validation.isStringPresent(firstName, "First Name");

}while(!errorCheck);

//Getting Email address and ensuring the string is there

do

{

System.out.print("Please enter the Employee's Email Address");

email = sc.nextLine();

errorCheck = Validation.isStringPresent(email, "Email Address");

}while(!errorCheck);

//Getting Social Security Number and ensuring its a 9 digit number and an integer

do

{

int min = 111111111;

int max = 999999999;

System.out.print("Please enter the Employees Social Security Number");

ssNumber = sc.nextLine();

errorCheck = Validation.isInteger(ssNumber, "Social Security Number");

errorCheck = Validation.isWithinRangeInteger(ssNumber, min, max, "Social Security Number");

System.out.println("The employee number is: " + Employee.getEmpNumber() );

System.out.print("would you like to continue?");

answer = sc.nextLine();

}while(answer.equalsIgnoreCase("y"));

}

else

{

//Setting variables for the Calculator

String empNum;

String lastName;

String firstName;

String email;

String ssNumber;

do

{

int min = 1000;

int max = 9999;

System.out.print("Please enter the Employee Number");

empNum = sc.nextLine();

errorCheck = Validation.isInteger(empNum, "Employee Number") && Validation.isWithinRangeInteger(empNum, min, max, "Employee Number");

}while(!errorCheck);

int empNumInt = Integer.parseInt(empNum);

//Getting Employee's last name

do

{

System.out.print("Please enter the Employee's Last Name");

lastName = sc.nextLine();

errorCheck = Validation.isStringPresent(lastName, "Last Name");

}while(!errorCheck);

System.out.print("would you like to continue?");

answer = sc.nextLine();

}while(answer.equalsIgnoreCase("y"));

}

}

}

Validation.java:

package presentation;

import java.text.NumberFormat;

import java.time.LocalDate;

import java.time.format.DateTimeParseException;

import java.math.*;

public class Validation

{

//*****************************************

/*this method tests to see if the user entered data into a String field.

You pass this method a String, then call a method from the String class called isEmpty()

if nothing is in the field, it will display an error message and return false, if the field is not empty

it will return a true

*/

public static boolean isStringPresent(String stringData, String title)

{

if(stringData.isEmpty())

{

System.out.println(title + " must be present, please re-enter: ");

return false;

}

return true;

}

//******************************************

/*This method tests to make sure that no characters are entered into a numeric field.

* The method accepts the data as a String, passes that data along with the field name to this method.

* Within the try statement, the String is parsed(changed to an integer). If there are no characters

* in the field, it returns a true(the data is good).

* If there are characters in the field, it drops to the catch statement, displays an error message,

* and returns a false.

*/

public static boolean isInteger(String intData, String title)

{

try

{

int i = Integer.parseInt(intData);

return true;

}

catch (NumberFormatException e)

{

System.out.println(title + " must be an integer. Please re-enter.");

return false;

}

}

//******************************************

/*This method tests to make sure that the user entered a valid range into the field.

* For example if you wanted to test an age, and the requirement was a minimum of 18 years old,

* that would be your min, and the maximum age couldn't be more than 120, that would be your max.

* This method accepts what the user entered as a String, then parses it to an Integer.

* You pass the min and max values that you want tested and a String that explains what is being tested.

* In my example above, the String that you pass would probably hold "Age", so that the error message

* would say "Age must be between 18 and 120, Please re-enter"

* The integer is tested to make sure that it falls with the ranges, if it does, it returns a true, if

* it does not, it returns a false.

*/

public static boolean isWithinRangeInteger(String intData, int min, int max, String title)

{

int i = Integer.parseInt(intData);

if (i < min | i > max)

{

System.out.println(title + " must be between " + min + " and " + max + ". " + " Please re-enter.");

return false;

}

return true;

}

//**************************************************

//method that tests for numeric data for a long integer

public static boolean isLong(String longData, String title)

{

try

{

long i = Long.parseLong(longData);

return true;

}

catch (NumberFormatException e)

{

System.out.println(title + " must be an integer. Please re-enter.");

return false;

}

}

//method that tests a range using a long integer

public static boolean isWithinRangeLong(String longData, long min, long max, String title)

{

long i = Long.parseLong(longData);

if (i < min | i > max)

{

System.out.println(title + " must be between " + min + " and " + max + ". " + " Please re-enter.");

return false;

}

return true;

}

//This method is the same as isInteger, but tests a double

public static boolean isDouble(String doubleData, String title)

{

try

{

double d = Double.parseDouble(doubleData);

return true;

}

catch (NumberFormatException e)

{

System.out.println(title + " must be a numeric value. Please re-enter.");

return false;

}

}

//******************************************

//This method is the same as isWithinRangeInteger, but tests a double

public static boolean isWithinRangeDouble(String doubleData, double min, double max, String title)

{

double d = Double.parseDouble(doubleData);

if (d < min | d > max)

{

System.out.println(title + " must be between " + min + " and " + max + ". " + " Please re-enter.");

return false;

}

return true;

}

//******************************************

//This method accepts a String argument, then tests it for a valid date

public static boolean isDateValid(String date)

{

try

{

LocalDate parsedDate = LocalDate.parse(date);//parses the String into a LocalDate object

return true;

}

catch (DateTimeParseException e)

{

System.out.println("Date must be in this format: yyyy-mm-dd & must be a valid date " + ". " + "Please re-enter.");

return false;

}

}

//**************************************************

/*This method allows you to round a number half up, which means

* that if you have a number for example 222.875, it rounds it to 222.88.

* The 2 in the setScale method is how many decimal places you want.

* This returns a BigDecimal object.

* BigDecimal rounds, but it doesn't format, that why I have the method below it that does both.

*/

public static BigDecimal formatRound(double number)

{

BigDecimal decimalRound = new BigDecimal(number);

return decimalRound = decimalRound.setScale(2, RoundingMode.HALF_UP);

}

//**************************************************************

/*This method both rounds by using the BigDecimal class and formats the

* number by using one of the NumberFormat class methods. You can use one of the

* two methods of the NumberFormat class that either adds a dollar sign

* or leaves the dollar sign off but still formats($2,211.55 or 2,211.55)

* This method returns a String

*/

public static String formatAndRound(double number)

{

NumberFormat num = NumberFormat.getCurrencyInstance();//dollar sign

//NumberFormat num = NumberFormat.getNumberInstance();//no dollar sign

BigDecimal decimalRound = new BigDecimal(number);

return num.format(decimalRound = decimalRound.setScale(2, RoundingMode.HALF_UP));

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

2. Describe why we form relationships

Answered: 1 week ago

Question

5. Outline the predictable stages of most relationships

Answered: 1 week ago