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

Textbook 7ed. P732 Q6 of PROGRAMMING PROJECTS as listed below: Write a program t

ID: 3704768 • Letter: T

Question

Textbook 7ed. P732 Q6 of PROGRAMMING PROJECTS as listed below:

Write a program to enter employee data, including SSN (Social Security Number) and salary into an array with maximum # of 100. Allow to enter less than 100 employees.

The program should use two exception class,

one called: when SSN entered without 2 dashes and not 9 digits

one called: when SSN entered has non digits

When an exception is thrown, tell user what is entered and why it is wrong, ask reenter again.

After all data has been entered, display the records for all employees in console statement, with an annotation stating whether the employee’s salary is above or below average.

Design the THM class derived from book sample class Person, then add all required private variables, constructors, getters (accessor), setters (mutator), and methods of override, and overload types.

The program begins with one O/P statement in GUI, to display the title and a greeting.

This program should be in java

Explanation / Answer

ExceptionNoDashNonNineDigitsSSN.java

==================================

package com.chegg;

public class ExceptionNoDashNonNineDigitsSSN extends Exception{

/**

* Custom Exception class called when SSN entered without 2 dashes and not 9 digits

*/

private static final long serialVersionUID = 1L;

ExceptionNoDashNonNineDigitsSSN(String ssn) {

super(ssn);

}

}

ExceptionWhenNonNumeralSSN.java

===================================

/**

*

*/

package com.chegg;

/**

* Custom Exception class called when SSN entered has non-numeral digits

*/

public class ExceptionWhenNonNumeralSSN extends Exception{

/**

*

*/

private static final long serialVersionUID = 1L;

ExceptionWhenNonNumeralSSN(String ssn) {

super(ssn);

}

}

Employee.java

=============

/**

*

*/

package com.chegg;

/**

* @author user

*

*/

public class Employee {

private Integer EmployeeId;

private String EmployeeName;

private String EmployeeSSN;

private Integer EmployeeSalary;

private String IsSalaryAboveAverage;

public Employee(Integer employeeId, String employeeName,String employeeSSN,

Integer employeeSalary) {

EmployeeId = employeeId;

EmployeeName = employeeName;

EmployeeSSN = employeeSSN;

EmployeeSalary = employeeSalary;

}

public Employee(Integer employeeId, String employeeName,

String employeeSSN, Integer employeeSalary,

String isSalaryAboveAverage) {

EmployeeId = employeeId;

EmployeeName = employeeName;

EmployeeSSN = employeeSSN;

EmployeeSalary = employeeSalary;

IsSalaryAboveAverage = isSalaryAboveAverage;

}

public Integer getEmployeeId() {

return EmployeeId;

}

public void setEmployeeId(Integer employeeId) {

EmployeeId = employeeId;

}

public String getEmployeeName() {

return EmployeeName;

}

public void setEmployeeName(String employeeName) {

EmployeeName = employeeName;

}

public String getEmployeeSSN() {

return EmployeeSSN;

}

public void setEmployeeSSN(String employeeSSN) {

EmployeeSSN = employeeSSN;

}

public Integer getEmployeeSalary() {

return EmployeeSalary;

}

public void setEmployeeSalary(Integer employeeSalary) {

EmployeeSalary = employeeSalary;

}

public String getIsSalaryAboveAverage() {

return IsSalaryAboveAverage;

}

public void setIsSalaryAboveAverage(String isSalaryAboveAverage) {

IsSalaryAboveAverage = isSalaryAboveAverage;

}

}

EmployeeReport.java

======================

/**

*

*/

package com.chegg;

import java.util.Scanner;

/**

* @author user

*

*/

public class EmployeeReport {

/**

* @param args

*

*/

public static void main(String[] args) {

System.out.println("Hi ! Welcome to the Employee Report");

Employee emp[]= new Employee[100];

Scanner sc=new Scanner(System.in);

for(int count=0; count<100; count++){

System.out.println("Enter the details for Employee # "+ (count+1));

System.out.println("Employee Id :");

Integer empId = sc.nextInt();

System.out.println("Employee Name :");

String empName = sc.next();

System.out.println("Employee SSN :");

String empSSN = validateEnteredSSN(sc.next());

System.out.println("Employee Salary :");

Integer empSal = sc.nextInt();

emp[count] = new Employee(empId,empName,empSSN,empSal);

}

Integer totalSalary =0;

for(int i=0; i<100;i++){

totalSalary = totalSalary + emp[i].getEmployeeSalary();

}

Double avgSalary = (double) (totalSalary/100);

  

//Overwriting every Employee Object with the Salary Above or below average

Employee newEmpObj[]=new Employee[100];

  

for(int i =0; i< 100; i++){

if(emp[i].getEmployeeSalary() < avgSalary){

newEmpObj[i] = new Employee(emp[i].getEmployeeId(),emp[i].getEmployeeName(),emp[i].getEmployeeSSN(),emp[i].getEmployeeSalary(),"Salary Below Average");

}else{

newEmpObj[i] = new Employee(emp[i].getEmployeeId(),emp[i].getEmployeeName(),emp[i].getEmployeeSSN(),emp[i].getEmployeeSalary(),"Salary Above Average");

}

}

System.out.println("FINAL RECORD OF ALL EMPLOYEES");

System.out.println("======================================================");

System.out.println("Employee ID Name SSN Salary Salary Indicator");

for(int k = 0; k<100;k++){

System.out.println(newEmpObj[k].getEmployeeId()+" "+newEmpObj[k].getEmployeeName()+" "+newEmpObj[k].getEmployeeSSN()+" "+newEmpObj[k].getEmployeeSalary()+" "+newEmpObj[k].getIsSalaryAboveAverage());

}

}

/*

* Private method to Validate SSN on 2 grounds

*

*/

private static String validateEnteredSSN(String empSSN) {

String finalSSNToBeReturned = null;

try{

int countOfDashes =0;

for (int i=0; i<empSSN.length(); i++)

{

if (empSSN.charAt(i) == '-')

countOfDashes++;

}

if(countOfDashes != 2){

String empSsnWithoutDash = (empSSN.replace("-", "")).trim();

int lengthofDigitsInSSN = 0;

for (int i = 0, len = empSsnWithoutDash.length(); i < len; i++) {

if (Character.isDigit(empSsnWithoutDash.charAt(i))) {

lengthofDigitsInSSN++;

}

}

if(lengthofDigitsInSSN != 9){

throw new ExceptionNoDashNonNineDigitsSSN("You ve entered SSN # "+empSSN +" which does not have 2 dashes and is a Non 9 digit number");

}

}

String empSsnWithoutDash = (empSSN.replace("-", "")).trim();

boolean doesSSNHaveNonDigit = empSsnWithoutDash.matches("^[0-9]+$");

if(!doesSSNHaveNonDigit){

throw new ExceptionWhenNonNumeralSSN("You ve entered SSN # "+empSSN +" which does not have all numeral characters");

}

finalSSNToBeReturned = empSSN;

}

catch (ExceptionNoDashNonNineDigitsSSN e) {

System.out.println(e.getMessage());

Scanner sc=new Scanner(System.in);

System.out.println("ReEnter SSN :");

String empSSN1 = sc.next();

validateEnteredSSN(empSSN1);

}

catch (ExceptionWhenNonNumeralSSN e) {

System.out.println(e.getMessage());

Scanner sc=new Scanner(System.in);

System.out.println("ReEnter SSN :");

String empSSN1 = sc.next();

validateEnteredSSN(empSSN1);

}

return finalSSNToBeReturned;

} // end of private method block

}

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