Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The book name is Java An introduction to problem sloving 7ed Plz give the code in java and it match with the output below. The

The book name is Java An introduction to problem sloving 7ed

Plz give the code in java and it match with the output below.

The Assignment:

Chapter 9:

Programming project 6: This project is found starting on page 732

Assignment Guidelines:

Write a program to enter employee data, including social security number and salary, into an array. The maximum number of employees is 100, but your program should also work for any number of employees less than 100. Your program should use two exception classes, one called SSNLengthException for when the social security number enteredwithout dashes or spacesis not exactly nine characters and the other called SSNCharacterException for when any character in the social security number is not a digit. When an exception is thrown, the user should be reminded of what she or he entered, told why it is inappropriate, and asked to reenter the data. After all data has been entered, your program should display the records for all employees, with an annotation stating whether the employees salary is above or below average. You will also need to define the classes Employee, SSNLengthException, and SSNCharacterException. Derive the classEmployee from the class Person in Listing 8.4 of Chapter 8. Among other things, the class Employee should have input and output methods, as well as constructors, accessor methods, and mutator methods. Every Employee object should record the employees name, salary, and social security number, as well as any other data you need or think is appropriate.

Note:

It may be useful to review arrays of objects before doing this project. For example, even after creating the array of EmployeeCh8 objects, it is necessary to create each element with a new statement inside the loop that reads in the employees information. Note that it is useful to use the same variable for the array subscript and the employees number, except that the subscript begins with 0 and the employee number begins with 1. So, whenever the employee number needs to be displayed, simply use the expression (subscript variable + 1).

References:

Listing 8.4, Practice Program 8.1

The assignment must have the following classes:

1. EmployeeChapter9, in file EmployeeChapter9.java

2. InvalidSSNCharacterException, in file InvalidSSNCharacterException.java

3. InvalidSSNLengthException, in file InvalidSSNLengthException.java

4. Person, in file Person.java

5. EmployeeDemo, in file EmployeeDemo.java

Sample Test:

Case 1 no errors:

----jGRASP exec: java EmployeeCh9Demo Enter employee #1's name: abc Enter employee #1's salary: 23000 Enter employee #1's SSN (9 digits): 234567890 Continue entering employees? (Y for Yes, or N for No) Y Enter employee #2's name: lmn Enter employee #2's salary: 56000 Enter employee #2's SSN (9 digits): 123456789 Continue entering employees? (Y for Yes, or N for No) N Employee #1 Name: abc Salary: 23000.0 SSN : 234567890 Below average Employee #2 Name: lmn Salary: 56000.0 SSN : 123456789 Above average No more employees. ----jGRASP: operation complete.

Case 2 Errors Exceptions:

----jGRASP exec: java EmployeeCh9Demo Enter employee #1's name: abc Enter employee #1's salary: 23000 Enter employee #1's SSN (9 digits): 345 345's length of 3 is invalid: it must be 9 characters. Re-enter data for employee #1 Continue entering employees? (Y for Yes, or N for No) Y Enter employee #1's name: abc Enter employee #1's salary: 23000 Enter employee #1's SSN (9 digits): 123456789 Continue entering employees? (Y for Yes, or N for No) Y Enter employee #2's name: lmn Enter employee #2's salary: 45000 Enter employee #2's SSN (9 digits): avc avc's length of 3 is invalid: it must be 9 characters. Re-enter data for employee #2 Continue entering employees? (Y for Yes, or N for No) Y Enter employee #2's name: lmn Enter employee #2's salary: 45000 Enter employee #2's SSN (9 digits): 12c67f789 12c67f789 is an invalid SSN: it contains an illegal character: c Re-enter data for employee #2 Continue entering employees? (Y for Yes, or N for No) Y Enter employee #2's name: lmn Enter employee #2's salary: 45000 Enter employee #2's SSN (9 digits): 234567890 Continue entering employees? (Y for Yes, or N for No) N Employee #1 Name: abc Salary: 23000.0 SSN : 123456789 Below average Employee #2 Name: lmn Salary: 45000.0 SSN : 234567890 Above average No more employees. ----jGRASP: operation complete.

Listing 8.4

public class Undergraduate extends Student { private int level; //1 for freshman, 2 for sophomore, //3 for junior, or 4 for senior.  public Undergraduate () { super (); level = 1; } public Undergraduate (String initialName, int initialStudentNumber, int initialLevel) { super (initialName, initialStudentNumber); setLevel (initialLevel); //Checks 1 <= initialLevel <= 4 } public void reset (String newName, int newStudentNumber, int newLevel) { reset (newName, newStudentNumber); //Students reset setLevel (newLevel); //Checks 1 <= newLevel <= 4 } public int getLevel () { return level; } public void setLevel (int newLevel) { if ((1 <= newLevel) && (newLevel <= 4)) level = newLevel; else { System.out.println ("Illegal level!"); System.exit (0); } } public void writeOutput () { super.writeOutput (); System.out.println ("Student Level: " + level); } public boolean equals (Undergraduate otherUndergraduate) { return equals ((Student) otherUndergraduate) && (this.level == otherUndergraduate.level); } } 

Listing 8.1

public class Person { private String name; public Person () { name = "No name yet"; } public Person (String initialName) { name = initialName; } public void setName (String newName) { name = newName; } public String getName () { return name; } public void writeOutput () { System.out.println ("Name: " + name); } public boolean hasSameName (Person otherPerson) { return this.name.equalsIgnoreCase (otherPerson.name); } } 

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

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

Recognize the power of service guarantees.

Answered: 1 week ago