Question
(1) Write a program to enter employee data, including SSN (Social Security Number) and salary into an array with maximum # of 100. Allow to
(1) 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. (2) The program should use two exception class, one called: SSNLengthException when SSN entered without 2 dashes and not 9 digits one called: SSNCharacterException when SSN entered has non digits (3) When an exception is thrown, tell user what is entered and why it is wrong, ask reenter again. (4) After all data has been entered, display the records for all employees in console statement, with an annotation stating whether the employees salary is above or below average. (5) 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. (6) The program source should be appropriately indented, points will be cut for unconventional, rude and messy codes. (7) The program begins with one O/P statement in GUI, to display the title, author, and ID (8) The program should be user friendly, informative, and display clear statements, points will be cut heavily if this specs not met.
i have this so far and i am having trouble adding a GUI statement. No clue where to start. (GUI based)
public class J22_PaulS_ MID_THM
import java.util.Scanner;
{
private String SSN;
private double salary;
public THM(String sSN, double salary)
{
super();
SSN = sSN;
this.salary = salary;
}
public String getSSN()
{
return SSN;
}
public void setSSN(String sSN)
{
SSN = sSN;
}
public double getSalary()
{
return salary;
}
public void setSalary(double salary)
{
this.salary = salary;
}
public String toString()
{
return "SSN : " + this.getSSN() + " Salary : " + this.getSalary();
}
}
public class THMTest
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.println("Enter employees(1 to 100 ) : ");
int n = s.nextInt();
THM[] empArr = new THM[n];
for (int i = 0; i < n; i++)
{
try
{
System.out.println("----Employee " + (i + 1) + " --");
System.out.println("Enter SSN :"); 1
String ssn = s.nextLine();
validateSSN(ssn);
System.out.println("Enter salary : ");
double salary = s.nextDouble();
THM = new THM(ssn, salary);
empArr[i] = thm;
}
catch (Exception e)
{
System.out.println(e.getMessage());
System.out.println("Retry entering details again");
--i;
}
}
for (int i = 0; i < empArr.length; i++)
{
System.out.println(empArr[i].toString());
}
}
public static boolean validateSSN(String ssn) throws SSNCharacterException, SSNLengthException
{
int digit_count = 0;
int dash_count = 0;
for (int i = 0; i < ssn.length(); i++)
{
if (Character.isDigit(ssn.charAt(i)))
{
digit_count++;
}
else if (ssn.charAt(i) == '-')
{
dash_count++;
}
else
{
throw new SSNCharacterException();
}
}
if (dash_count != 2)
{
throw new SSNLengthException(1);
}
if (digit_count != 9)
{
throw new SSNLengthException(2);
}
return (digit_count == 9) && (dash_count == 2);
}
}
public class SSNLengthException extends Exception
{
private String errorCode1 = "SSNLengthException : SSN doesn't contain exactly 2 dashes";
private String errorCode2 = "SSNLengthException : SSN doesn't contain exactly 9 digits";
private String currentError;
public SSNLengthException(int codeNum)
{
switch (codeNum)
{
this.currentError = errorCode1;
break;
this.currentError = errorCode2;
break;
}
}
public String getMessage()
{
return this.currentError;
}
public String toString()
{
return this.currentError;
}
}
public class SSNCharacterException extends Exception
{
private String errorCode = "SSNCharacterException : SSN contains non-digits";
public SSNCharacterException()
{
}
public String getMessage()
{
return this.errorCode;
}
public String toString()
{
return this.errorCode;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started