Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How would I code a Presentation class with what I already have? The presentation

ID: 3750040 • Letter: H

Question

How would I code a Presentation class with what I already have? The presentation class should ask for the employee number, last name, first name, email address and social security number. The presentation class’s main method should consist almost entirely of method calls. Error checking should be done on all user-entered fields using a Validation class. Once the fields have been validated, those values should be passed to business class using the set methods. 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 set method. 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 user’s information by calling an overridden 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

public abstract class Employee {

//Declaring instance variables

private int empNo;

private String firstname;

private String lastname;

private String email;

private String socialSecurityNumber;

  

public Employee() {

  

}

//Parameterised constructor

public Employee(int empNo,String firstname, String lastname,String email,String socialSecurityNumber) {

this.empNo=empNo;

this.firstname = firstname;

this.lastname = lastname;

this.email=email;

this.socialSecurityNumber = socialSecurityNumber;

}

//Setters and Getters.

public String getFirstname() {

return firstname;

}

public void setFirstname(String firstname) {

this.firstname = firstname;

}

public String getLastname() {

return lastname;

}

public void setLastname(String lastname) {

this.lastname = lastname;

}

public String getSocialSecurityNumber() {

return socialSecurityNumber;

}

public void setSocialSecurityNumber(String socialSecurityNumber) {

this.socialSecurityNumber = socialSecurityNumber;

}

  

public String getEmail() {

return email;

}

public void setEmail(String email) {

this.email = email;

}

public abstract double calcPay(double n);

@Override

public String toString() {

System.out.println("Firstname :"+getFirstname());

System.out.println("Lastname :"+getLastname());

System.out.println("Email :"+email);

System.out.println("Social Security No :"+getSocialSecurityNumber());

return " ";

}

}

___________________

HourlyEmployee.java

public class HourlyEmployee extends Employee {

//Declaring instance variables

private final double HOURLYWAGE=15.75;

private int hoursworked;

//Parameterised constructor

public HourlyEmployee(int empNo,String firstname, String lastname,String email, String ssn,

double hourlyWage, int hoursworked) {

super(empNo,firstname,lastname,email,ssn);

this.hoursworked=hoursworked;

  

}

//Setters and Getters.

public int getHoursworked() {

return hoursworked;

}

public void setHoursworked(int hoursworked) {

if(hoursworked>0 && hoursworked<=168)

{

this.hoursworked = hoursworked;   

}

  

}

//toString() method will display the contents of the Object.

@Override

public String toString() {

System.out.print("Hourly Employee:");

super.toString();

System.out.println("Hours Worked :"+getHoursworked());

System.out.println("Earnings :"+calcPay(hoursworked));

  

return " ";

}

@Override

public double calcPay(double n) {

return n*HOURLYWAGE;

}

}

__________________

SalariedEmployee.java

public class SalariedEmployee extends Employee {

// Declaring instance variables

private double ysalary;

// Parameterised constructor

public SalariedEmployee(int empNo,String firstname, String lastname, String email,

String ssn, double ysalary) {

super(empNo,firstname, lastname, email, ssn);

this.ysalary = ysalary;

}

// Setters and Getters.

public double getSalary() {

return ysalary;

}

public void setSalary(double salary) {

if (salary > 0) {

this.ysalary = salary;

}

}

// toString() method will display the contents of the Object.

@Override

public String toString() {

System.out.print("Salaried Employee:");

super.toString();

System.out.println("Salary: : " + getSalary());

System.out.println("Earnings: " + calcPay(ysalary));

return " ";

}

@Override

public double calcPay(double n) {

return n / 12;

}

}

__________________

Explanation / Answer

package morningchegg; import java.util.Scanner; public class Presentation extends Employee{ public static void main(String args[]) { Scanner s = new Scanner(System.in); /* Prompting user to input employee number */ System.out.println("Enter your employee number "); int employeenumber = s.nextInt(); if (!new Validation().validateemployeenumber(employeenumber)) { System.out.println("Your employeenumber is not a valid one please enter value greater than 0"); } System.out.println("Your employeenumber is " + employeenumber); /* Prompting user to input first name */ System.out.println("Enter your firstname "); String firstname = s.nextLine(); if (!new Validation().validatefirsname(firstname)) { System.out.println("Your firstname is empty or null"); } System.out.println("Your firstname is " + firstname); /* Prompting user to input last name */ System.out.println("Enter your lastname "); String lastname = s.nextLine(); if (!new Validation().validatelastname(lastname)) { System.out.println("Your lastname is empty or null"); } System.out.println("Your lastname is " + lastname); /* Prompting user to input social security number */ System.out.println("Enter your social security number "); String ssn = s.nextLine(); if (!new Validation().validatesocialsecurity(ssn)) { System.out.println("Your social security is empty or null"); } System.out.println("Your social security number is " + ssn); /* Prompting user to email Address */ System.out.println("Enter your email Address"); String emailaddress = s.nextLine(); if (!new Validation().validateemail(emailaddress)) { System.out.println("Your email is empty or null or is not a valid email address"); } System.out.println("Your emailaddress is " + emailaddress); Presentation p = new Presentation(employeenumber, firstname, lastname, emailaddress, ssn); System.out.println("Are the employee is hourly or salary"); String type = s.nextLine(); switch(type){ case "hourly": System.out.println("Enter the number of hours worked"); int hours = s.nextInt(); HourlyEmployee hremp = new HourlyEmployee(employeenumber, firstname, lastname, emailaddress, ssn,23.23, hours); double pay = hremp.calcPay(hremp.getHoursworked()); System.out.println("The pay of the employee is " + pay); hremp.toString(); case "salary": System.out.println("Calculating the yearly salary"); SalariedEmployee asd = new SalariedEmployee(employeenumber, firstname, lastname, emailaddress, ssn,31321); double salary = asd.calcPay(3); System.out.println("The pay of the employee is for the given month" + salary); asd.toString(); default: System.out.println("Please enter the right salary amount to start working"); } } Presentation(int employeenumber,String firstname,String lastname,String emailaddress,String ssn){ super(employeenumber, firstname, lastname, emailaddress, ssn); } @Override public double calcPay(double n) { return 0; } } package morningchegg; public class Validation { public boolean validateemployeenumber(int empno){ if(empno > 0 && empno 0 && hoursworked 0) { this.ysalary = salary; } } // toString() method will display the contents of the Object. @Override public String toString() { System.out.print("Salaried Employee:"); super.toString(); System.out.println("Salary: : " + getSalary()); System.out.println("Earnings: " + calcPay(ysalary)); return " "; } @Override public double calcPay(double n) { return n / 12; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote