Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write java code for the following instructions Assignment 2 Extend your application from the previous assignment. The class name should be Controller2, an underscore,

Please write java code for the following instructions
Assignment 2
Extend your application from the previous assignment. The class name should be Controller2, an
underscore, and your NetID run together; for example, if your NetID is abcde6, your class name would be
Controller2_abcde6. Likewise, Employee should be renamed Employee2. For this assignment, we will
create text-based tools for managing employee records. All requirements from the previous assignment
remain in effect for the new classes. The new features for this application are:
1) For Employee2, add set methods for ssn and employeeId.
2) For the Controller2 class generally:
a. The constructor should create the Employee2 array e initial size zero.
b. Data fields in Employee2 objects should be assigned new values using the
corresponding set methods and read them using the corresponding get methods.
c. Write a method ePlus that accepts the Employee2 array e as a parameter and returns an
Employee array. The returned array should be one element larger than e and contain all
elements of e in the same indexes. To expand e, use: e = ePlus(e);.
d. Write a method eMinus that accepts an int index as a parameter and returns an
Employee array. The returned array should be one element smaller than e and without
the element at index index. The elements in the returned array should otherwise maintain
the same order as in e. To delete an element at index index, use: e = eMinus(index);.
3) In the Controller2 getInput method, write a method for each valid command:
a. add: increases the size of e by one by calling ePlus, then creates a new Employee2
object and adds it to the last valid index of e. To create the Employee2 object, the
application will prompt the user to enter values for each of the six Employee2 data fields,
in order: employeeId, lastName, firstName, department, jobTitle, and ssn. The full set of
data fields will all be entered on one line, separated by single spaces, and parsed by a
StringTokenizer object.
b. delete: decreases the size of e by one. The user will be prompted to enter an index value,
then delete that index by calling eMinus
c. update employee: the user will be prompted for an index value, then display via the
console the Employee2 fields for e[index], separated by tabs ( ), in order: employeeId,
lastName, firstName, department, jobTitle, and ssn. Then, the user will be prompted to
enter a new set of six data values in the same order. As in 2a), The full set of data fields
will all be entered on one line, separated by single spaces, and parsed by a
StringTokenizer object.
d. update field values: the user will be prompted to enter either department or jobTitle,
then an old value String, then a new value String, all on one line, separated by spaces,
and parsed by a StringTokenizer object. Within the entered field, any Strings matching
the old value will be updated to the new value. For example, if the user enters jobTitle
intern associate, then any Employee2 objects where jobTitle is intern will have that
data field changed to associate.
e. read: On the console, the application will display one line for each Employee2 in e. The
Employee2 objects will be ordered by index, and each line will contain, separated by tabs
( ), in order: the index, employeeId, lastName, firstName, department, jobTitle, and ssn.
f. exit: displays a message via the console, Thank you for using our Employee
Management Application, then calls the method System.exit(0);
Additional Constraints
As before, the program should be implemented as a single file containing the two Java classes Controller2
and Employee2. All data members should be declared as private; all methods should be declared without
any visibility modifiers. It is not necessary to provide error-checking for this application; you may safely
assume that the user will only enter valid inputs. However, please carefully follow the formats given;
points will be deducted for non-standard input formats.
Assignment 1 (For reference to solve Assignment 2)
Create a program for managing an employee database. The required functionality is:
1) An Employee class, with the following methods and attributes:
a. Data members: firstName (String), lastName (String), ssn (long), employeeId (int),
department (String), and jobTitle (String).
b. Constructor methods:
One method requiring parameters for firstName, lastName, ssn, and employeeId.
Department and jobTitle will be assigned default values of unknown.
One method requiring parameters for firstName, lastName, ssn, employeeId,
department, and jobTitle
c. Set methods for changing firstName, lastName, department, and jobTitle which accept
a single String as a parameter for updating the preexisting String.
d. Get methods for returning each of the attributes in 1a.
2) A Controller class to manage the addition, updating, and viewing of employees
a. Data members:
An array of Employee objects named e, just declared (not created)
An int variable named counter (for the number of employees), initialized to zero
A Scanner object named scanner for text input
b. A getInput method containing a loop for repeatedly receiving text input via scanner. Prior
to receiving each input, the program will display the prompt please enter your action.
The following inputs will be accepted and the program will respond with:
add: respond with please enter employee data
delete: respond with delete which employee(s)?
update employee: respond with update which employee(s)?
update field values: respond with update which field values?
read: respond with read which employee(s)?
exit: respond with thank you for using the EDB application!
c. Other than exit, the response text will be followed by an empty line and a repeat prompt.
The exit command will exit the program by calling System.exit(0).
d. Controller will have a main method that creates a Controller object named c and calls cs
getInput method.
Additional Constraints
The program should be implemented as a single file containing both classes. Each of the required
functionalities should be implemented as separate methods (as far as possible) and operate by passing
parameters and/or returning values. Comments should be provided for the class and for each variable
and method, briefly explaining their usage.

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

' Which areas are you most dependent on to get your work done?

Answered: 1 week ago