SlideShare a Scribd company logo
1 of 9
1 Goals.
1. To use a text file for output and later for input.
2. To use exceptions and write an exception handler that does
more than abort execution.
3. To Use a static class variable.
4. To use a boolean variable and a Date variable.
5. To use an ArrayList.
6. To implement Phase 1 of a four phase well-structured project
with multiple classes using the Model-View-Controller design
pattern (MVC).
2 Overview
This section discusses a finished application that you will
construct in several phases. When all phases are finished, it will
simulate a human resources system to keep track of savings
through the company. There is a Human Resources Manager
(Boss), and employees (eventually more than one type of
employee will be used). Eventually, this system will be created
as an application with a windows interface. The Employee’s
login name will eventually be encrypted and the data will be
stored in an object file. Program 4 implements only part of the
menu, uses a text file and does not encrypt the employee data.
At first this will be a menu-driven application allowing for
these actions:
1. The first time the program is used, the user will enter his or
her own data in to the program and will become the Boss
(Human Resources Manager) with access to everyone’s data.
2. After that, when the program starts up, it will read in a
database of employee data and store it in the employee
collection.
3. After that, the Boss will be able to log in and create new
employees by entering the person’s name (first, middle initial-
optional, and last), login name, base salary, and savings
percent. This data will be used to initialize a new employee
object. The object will also record the current date and a unique
ID number for this employee. The new employee will be added
to the Employee collection.
4. The Boss can log in and display a list of all Employees in the
collection and can change the base salary or percent savings for
any employee. In the list, display the full name (first, middle
initial and last), login name, Employee ID, base salary, percent
savings and date of hire for each Employee.
5. Any Employee in the collection can log in and see his or her
own data and change their name and percent savings (due to
marriage, etc).
6. An Employee whose login name is in the collection may log
in and out. Logging in will automatically log out the prior
Employee.
7. The menu has an option to quit and quitting will cause the
final contents of the collection to be written back to the
database file (replacing it).
8. Since you have
more than one class
in this project, you will
need to create a package (call it “savings” – note the first letter
is lower case)
and put all of the classes in the package. To tell your program
to look for the other classes, you need to put the following in
each class file near your import statements.
package
savings;
3 The Employee Class: Superclass of the Model (from MVC) for
this application.
a) An object of type Employee will have the following data
members:
i)
A
static
int variable called nextId. See the detailed instructions below.
This is to make sure that the Employee ID is not re-used.
There is one of these for the class and we use it to set the
employee ID.
ii) The Employee ID is a
final
int variable. It cannot be updated. In your output, it should be
printed as a five digit number with leading zeros (use printf
with the format “%05d” so it looks like this 00001).
iii) The Employee’s name. When entered, it can include spaces
and punctuation, and will be terminated by the end of line
character. Store it as a single String. The name should be
entered as Last name, first name and middle initial (optional).
iv) Login name
has no spaces
and it can contain letters or numbers. It
must be at least 6 characters long.
For Program 5 you will have to make this unique in the database
(no duplicates).
When an employee logs-in they use this data member (we have
not implemented password yet).
v) The base salary (a double).
vi) The percent savings (a double).
vii) Date variable, set to the date that the employee was entered
in to the system.
viii) A boolean variable that is set to true, isEmployee. False
means this employee is no longer an employee and should not
be paid or be allowed to add to their company savings.
b) Provide a constructor with four parameters (login, name,
salary and percent savings) that initializes all Employee data
members.
c) Provide a constructor with all data members as parameters
that reads the data from the file and adds an instance of the
Employee class to the ArrayList or other collection and
initializes all Employee data members.
d) Do not implement get functions (accessors) for variables
unless they are needed. You will need them at some point, but
you may not need any accessors for P4.
e) Implement a set function for the salary, percent savings and
name. These are known as mutators.
f) Implement a toString() function that will format the data
members of Employee. Put each Employee on a single line of
the output. Include the ID, login name, name, salary, percent
savings, and date of hire separated by tab characters.
2)
The Employee ID
The employee ID number will be generated by the system,
using the static class member Employee.nextId
. The Boss will become employee ID 0. Each time an employee
is created, the nextID must be copied in to that employee’s ID
number, then nextId must be incremented. In this way no two
employees can have the same ID. In your output and file, make
this a system generated variable that is five digits long and
starts with 00001 (00000 for the Boss) and goes up from there.
An Employee ID number cannot be reused.
4 The main() function for P4:
The main() function When the file is saved, the nextID number
must be saved on the file first before the ArrayList data is
saved. When the file is read, the value of the nextID number
must be initialized (via the mutator function setId) to the saved
value from the file.
Main can be in a separate class called Main or it can be inside
the Savings class.
method should print a title line to the
console showing the program name and your name.
Then it should instantiate a Savings object and call the Savings
object’s doMenu() function.
When caught, print a comment, a stack trace, and abort.
execution terminates for any reason, the data in the collection
must be written back out to the file. This means you need a
finally block following the main’s try block. Do the following:
1. First, reopen the input file for output. This will destroy the
original contents of the file.
2. Then execute a “serialize” operation: write each object in the
collection to the file using a loop.
3. Lastly, close the new database file.
5 The Savings Class for P4: the controller class (from MVC) of
this application.
a. The Savings class should contain an ArrayList of Employee,
and variables to store the current Employee (a reference to an
Employee in the ArrayList), a menu, a Scanner for the
keyboard, a Scanner for the Employee-file, and a PrintWriter
for the Employee file.
b.
You may use this to define the menu:
private static String menu =
“Savings System Menunt1. Log In n”
+ “
t2. Enter employees nt3. List employees”
+ “
nt4. Change employee data nt5. Terminate an employee”
+
nt6. Report employee savings nt0. Exit system”
c. Use a switch statement to process the menu choices. Write a
separate function for each option! They will be necessary when
we convert the application to a GUI.
d. In program 4, we will implement menu options 1, 2, and 0.
5.1 The Savings constructor.
e. The first time this program is run, the file of Employee data
(employee file) will not exist. On second and further runs, it
will exist. The Exception system allows us to implement the
right functionality using a try..catch. Enclose the file handling
in a try block and write a catch block for
FileNotFoundException
. Note: an IOException should not happen because of the way
you have set up your program to prevent it by checking the
input data. If it does, let the exception pass up to main. You do
not need to handle it here.
The try block should do the following:
i. Open the Employee file and a Scanner to read it.
ii. Read all of the data one line at a time using a normal loop
and hasNext(). Create a series of Employee objects and store
them in the Employee collection (ArrayList).
iii. Close the Scanner (which closes the input file).
The catch block should do the following:
iv. This is the handler for a FileNotFoundException, which will
occur the first time this program is run and anytime you delete
the data file. If the file exists (second and later execution), this
error will not occur.
v. Print a clear comment about the missing file.
vi. Prompt the user for the logon name, salary, percent savings
and name of the boss, create an Employee object with ID
Number 0 and add it to the empty
Program 4: Employee Savings Database
CSCI 6617 Spring 2016
4
Employee collection (ArrayList). Then continue with normal
execution of this application, DO NOT ABORT.
f. At this point, the data from the file has been read, if it
existed. The next step is to open an output file with the same
name as the now-closed input file (replace it).
i. Put this code in second a try block that immediately follows
the catch block from the earlier try.
ii. Control will come here after the first try-block or its catcher
finishes its work. Notice that we are reentering execution after
an exception.
iii. At the end of the constructor, the program, its Employee
ArrayList, and its output file are ready for use.
4.2 The doMenu() function
Write a main loop that displays the menu forever (an infinite
loop), until the user selects ”0. Exit System”.
iv. Put the entire menu loop in a try block with a finally clause.
1. In the finally clause, write all of the Employees in the
Employee ArrayList to the output file using a loop, close the
file, and print a message on the console screen saying this was
completed.
2. After the finally block, control should return to main, where
it hits the end of another try block and ends the program.
v. Prompt the user for a menu choice and process that choice
with a switch. Do not use an if. . . else structure.
1. In the switch, do NOTHING except call one of the functions
below. When the program is converted to Java FX, this switch
will be replaced by a bunch of Buttons and other objects.
2. Break out of both the switch and the infinite loop if the user
selects
”0. Exit System”
. Leaving the loop will end the try block, which will send
control directly to the finally block.
3. Create an empty method (stub) to process each of the
following
“3. List employees”,
“
4. Change employee data”, “5. Terminate employees” and “6.
Pay employees”
because these menu choices are not implemented in P4.
Savings needs public functions for the menu options.
i.
The Savings class needs a private utility function, login() to
implement ”1. Log In”
.
4. login() prompts the user to enter their
login name
and checks the Employee ArrayList to see if they are an
Employee (if that Login Name is in the collection).
5. If the user is not in the Employee collection, they cannot
proceed. Print a message saying so and allow them to return to
the menu.
ii. newEmployee(): to create a new Employee member (about
20-30 lines of code, including whitespace and comments). This
is run when there are no employees in the ArrayList or when “2
Enter Employees” is chosen by the Boss (when logged in
Employee ID is 0).
6. Prompt for and read the Employee person's full name (assume
that there is a first and last name, but make the middle initial
optional. Allow for a hyphen in the last name), and the other
data members (fields).
7. Create a new Employee with this data and put it into the
ArrayList of Employees.
Program 4: Employee Savings Database
CSCI 6617 Spring 2016
5
iii. No function is needed for the ”0 Exit the System” menu
item. Just break out of the loop.
8. Break out of both the switch and the infinite loop if the user
selects
”0 Exit the System”
.
9. Leaving the loop will end the try block, which will send
control directly to the finally block.
6 Testing and Submission.
Due by 11:59 PM on the due date.
When you are sure your program works, delete the input and
output files. Then follow the testing procedure below.
1. Start the program and enter your own name. Make up the data
(name, logon name, salary and percent savings). Enter this user
as the Boss.
2. Add a second user you made up.
3. Exit the system.
4. Make a copy of the database file and make its name run1.txt
and copy and paste your console output to a file called
console1.txt (you can use notepad to save this).
5. Start the program again. Enter two more users – make them
up. This makes four users in total.
6. Exit the system.
Use the two runs to test errors in entering the data. Finally,
hand in a zipped folder containing:
Employee classes and Main if you created one).
and paste them in to the same file, but clearly mark them as run
1 and run 2 console output.

More Related Content

Similar to 1 Goals. 1. To use a text file for output and later for in.docx

Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablescis247
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesccis224477
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesccis224477
 
CS 2336 PROJECT 3 – Linked Inventory Management Project Due 1104 b.docx
CS 2336 PROJECT 3 – Linked Inventory Management Project Due 1104 b.docxCS 2336 PROJECT 3 – Linked Inventory Management Project Due 1104 b.docx
CS 2336 PROJECT 3 – Linked Inventory Management Project Due 1104 b.docxmydrynan
 
Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7helpido9
 
C programming session 09
C programming session 09C programming session 09
C programming session 09Dushmanta Nath
 
Cis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universityCis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universitylhkslkdh89009
 
Open a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdfOpen a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdfNathan2rSPeakes
 
Open a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdfOpen a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdflonkarhrishikesh
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docxgilbertkpeters11344
 
Program Specifications Develop an inventory management system for an e.docx
Program Specifications Develop an inventory management system for an e.docxProgram Specifications Develop an inventory management system for an e.docx
Program Specifications Develop an inventory management system for an e.docxVictormxrPiperc
 
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docxLab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docxDIPESH30
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxAgusto Sipahutar
 
Please be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxPlease be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxlorindajamieson
 
show code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdfshow code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdfAlanSmDDyerl
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classsdjdskjd9097
 
Django tutorial
Django tutorialDjango tutorial
Django tutorialKsd Che
 
Program Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docxProgram Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docxsharold2
 
Program Specifications in c++ Develop an inventory management syste.docx
Program Specifications in c++    Develop an inventory management syste.docxProgram Specifications in c++    Develop an inventory management syste.docx
Program Specifications in c++ Develop an inventory management syste.docxsharold2
 

Similar to 1 Goals. 1. To use a text file for output and later for in.docx (20)

Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variables
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
 
Cis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfacesCis247 a ilab 4 composition and class interfaces
Cis247 a ilab 4 composition and class interfaces
 
CS 2336 PROJECT 3 – Linked Inventory Management Project Due 1104 b.docx
CS 2336 PROJECT 3 – Linked Inventory Management Project Due 1104 b.docxCS 2336 PROJECT 3 – Linked Inventory Management Project Due 1104 b.docx
CS 2336 PROJECT 3 – Linked Inventory Management Project Due 1104 b.docx
 
Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7
 
C programming session 09
C programming session 09C programming session 09
C programming session 09
 
Cis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universityCis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry university
 
Open a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdfOpen a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdf
 
Open a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdfOpen a new project in Visual Studio Community and name it in the form.pdf
Open a new project in Visual Studio Community and name it in the form.pdf
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
 
Program Specifications Develop an inventory management system for an e.docx
Program Specifications Develop an inventory management system for an e.docxProgram Specifications Develop an inventory management system for an e.docx
Program Specifications Develop an inventory management system for an e.docx
 
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docxLab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
 
Lab 1 Essay
Lab 1 EssayLab 1 Essay
Lab 1 Essay
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptx
 
Please be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docxPlease be advised that there are four (4) programs just like this on.docx
Please be advised that there are four (4) programs just like this on.docx
 
show code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdfshow code and all classes with full implementation for these Program S.pdf
show code and all classes with full implementation for these Program S.pdf
 
Cis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee classCis247 i lab 2 of 7 employee class
Cis247 i lab 2 of 7 employee class
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
 
Program Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docxProgram Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docx
 
Program Specifications in c++ Develop an inventory management syste.docx
Program Specifications in c++    Develop an inventory management syste.docxProgram Specifications in c++    Develop an inventory management syste.docx
Program Specifications in c++ Develop an inventory management syste.docx
 

More from honey690131

PaperSelect one of the quality topics in healthcare from th.docx
PaperSelect one of the quality topics in healthcare from th.docxPaperSelect one of the quality topics in healthcare from th.docx
PaperSelect one of the quality topics in healthcare from th.docxhoney690131
 
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docx
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docxPart 1 - Microsoft AccessView GlossaryUse Access to create a.docx
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docxhoney690131
 
Part 1 - Microsoft Access 2019Use Access to create a database to.docx
Part 1 - Microsoft Access 2019Use Access to create a database to.docxPart 1 - Microsoft Access 2019Use Access to create a database to.docx
Part 1 - Microsoft Access 2019Use Access to create a database to.docxhoney690131
 
ParkinsonsPathophysiology, progression of disease, complication.docx
ParkinsonsPathophysiology, progression of disease, complication.docxParkinsonsPathophysiology, progression of disease, complication.docx
ParkinsonsPathophysiology, progression of disease, complication.docxhoney690131
 
Parenting Practices among DepressedMothers in the Child Welf.docx
Parenting Practices among DepressedMothers in the Child Welf.docxParenting Practices among DepressedMothers in the Child Welf.docx
Parenting Practices among DepressedMothers in the Child Welf.docxhoney690131
 
Parental InfluencesMerging science and business, selective bre.docx
Parental InfluencesMerging science and business, selective bre.docxParental InfluencesMerging science and business, selective bre.docx
Parental InfluencesMerging science and business, selective bre.docxhoney690131
 
Paragraph Structure with Use of Text(P) Topic Sentence-(I).docx
Paragraph Structure with Use of Text(P) Topic Sentence-(I).docxParagraph Structure with Use of Text(P) Topic Sentence-(I).docx
Paragraph Structure with Use of Text(P) Topic Sentence-(I).docxhoney690131
 
Paper should explain the difficulties on the Use of government trave.docx
Paper should explain the difficulties on the Use of government trave.docxPaper should explain the difficulties on the Use of government trave.docx
Paper should explain the difficulties on the Use of government trave.docxhoney690131
 
paper should be between 750 – 1500 words. APA formatting is required.docx
paper should be between 750 – 1500 words. APA formatting is required.docxpaper should be between 750 – 1500 words. APA formatting is required.docx
paper should be between 750 – 1500 words. APA formatting is required.docxhoney690131
 
Paper Requirements 4 pages (including title page, 2 pages .docx
Paper Requirements 4 pages (including title page, 2 pages .docxPaper Requirements 4 pages (including title page, 2 pages .docx
Paper Requirements 4 pages (including title page, 2 pages .docxhoney690131
 
Paper RequirementsRequired topic headings for your paper shou.docx
Paper RequirementsRequired topic headings for your paper shou.docxPaper RequirementsRequired topic headings for your paper shou.docx
Paper RequirementsRequired topic headings for your paper shou.docxhoney690131
 
Paper must be double spaced, with 12 point font and include section .docx
Paper must be double spaced, with 12 point font and include section .docxPaper must be double spaced, with 12 point font and include section .docx
Paper must be double spaced, with 12 point font and include section .docxhoney690131
 
Paper OrganizationStart with a title page and organize your pa.docx
Paper OrganizationStart with a title page and organize your pa.docxPaper OrganizationStart with a title page and organize your pa.docx
Paper OrganizationStart with a title page and organize your pa.docxhoney690131
 
Paper on topic  Date visualization A critical evaluation of its ar.docx
Paper on topic  Date visualization A critical evaluation of its ar.docxPaper on topic  Date visualization A critical evaluation of its ar.docx
Paper on topic  Date visualization A critical evaluation of its ar.docxhoney690131
 
PAPER EXPECTATIONSFollow the instructions.Make your ideas .docx
PAPER EXPECTATIONSFollow the instructions.Make your ideas .docxPAPER EXPECTATIONSFollow the instructions.Make your ideas .docx
PAPER EXPECTATIONSFollow the instructions.Make your ideas .docxhoney690131
 
Paper Instructions 5) Paper should be 5-7 pages (excluding title pag.docx
Paper Instructions 5) Paper should be 5-7 pages (excluding title pag.docxPaper Instructions 5) Paper should be 5-7 pages (excluding title pag.docx
Paper Instructions 5) Paper should be 5-7 pages (excluding title pag.docxhoney690131
 
Paper format and information4-5 pages in length.Papers mu.docx
Paper format and information4-5 pages in length.Papers mu.docxPaper format and information4-5 pages in length.Papers mu.docx
Paper format and information4-5 pages in length.Papers mu.docxhoney690131
 
Paper in Health care quality management strategies - recent arti.docx
Paper in Health care quality management strategies - recent arti.docxPaper in Health care quality management strategies - recent arti.docx
Paper in Health care quality management strategies - recent arti.docxhoney690131
 
Paper 2 Assignment POT 2002.Assignment Write a 1000 wor.docx
Paper 2 Assignment POT 2002.Assignment Write a 1000 wor.docxPaper 2 Assignment POT 2002.Assignment Write a 1000 wor.docx
Paper 2 Assignment POT 2002.Assignment Write a 1000 wor.docxhoney690131
 
Paper detailsUnit 4 Discussion Prompt1. What is the .docx
Paper detailsUnit 4 Discussion Prompt1. What is the .docxPaper detailsUnit 4 Discussion Prompt1. What is the .docx
Paper detailsUnit 4 Discussion Prompt1. What is the .docxhoney690131
 

More from honey690131 (20)

PaperSelect one of the quality topics in healthcare from th.docx
PaperSelect one of the quality topics in healthcare from th.docxPaperSelect one of the quality topics in healthcare from th.docx
PaperSelect one of the quality topics in healthcare from th.docx
 
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docx
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docxPart 1 - Microsoft AccessView GlossaryUse Access to create a.docx
Part 1 - Microsoft AccessView GlossaryUse Access to create a.docx
 
Part 1 - Microsoft Access 2019Use Access to create a database to.docx
Part 1 - Microsoft Access 2019Use Access to create a database to.docxPart 1 - Microsoft Access 2019Use Access to create a database to.docx
Part 1 - Microsoft Access 2019Use Access to create a database to.docx
 
ParkinsonsPathophysiology, progression of disease, complication.docx
ParkinsonsPathophysiology, progression of disease, complication.docxParkinsonsPathophysiology, progression of disease, complication.docx
ParkinsonsPathophysiology, progression of disease, complication.docx
 
Parenting Practices among DepressedMothers in the Child Welf.docx
Parenting Practices among DepressedMothers in the Child Welf.docxParenting Practices among DepressedMothers in the Child Welf.docx
Parenting Practices among DepressedMothers in the Child Welf.docx
 
Parental InfluencesMerging science and business, selective bre.docx
Parental InfluencesMerging science and business, selective bre.docxParental InfluencesMerging science and business, selective bre.docx
Parental InfluencesMerging science and business, selective bre.docx
 
Paragraph Structure with Use of Text(P) Topic Sentence-(I).docx
Paragraph Structure with Use of Text(P) Topic Sentence-(I).docxParagraph Structure with Use of Text(P) Topic Sentence-(I).docx
Paragraph Structure with Use of Text(P) Topic Sentence-(I).docx
 
Paper should explain the difficulties on the Use of government trave.docx
Paper should explain the difficulties on the Use of government trave.docxPaper should explain the difficulties on the Use of government trave.docx
Paper should explain the difficulties on the Use of government trave.docx
 
paper should be between 750 – 1500 words. APA formatting is required.docx
paper should be between 750 – 1500 words. APA formatting is required.docxpaper should be between 750 – 1500 words. APA formatting is required.docx
paper should be between 750 – 1500 words. APA formatting is required.docx
 
Paper Requirements 4 pages (including title page, 2 pages .docx
Paper Requirements 4 pages (including title page, 2 pages .docxPaper Requirements 4 pages (including title page, 2 pages .docx
Paper Requirements 4 pages (including title page, 2 pages .docx
 
Paper RequirementsRequired topic headings for your paper shou.docx
Paper RequirementsRequired topic headings for your paper shou.docxPaper RequirementsRequired topic headings for your paper shou.docx
Paper RequirementsRequired topic headings for your paper shou.docx
 
Paper must be double spaced, with 12 point font and include section .docx
Paper must be double spaced, with 12 point font and include section .docxPaper must be double spaced, with 12 point font and include section .docx
Paper must be double spaced, with 12 point font and include section .docx
 
Paper OrganizationStart with a title page and organize your pa.docx
Paper OrganizationStart with a title page and organize your pa.docxPaper OrganizationStart with a title page and organize your pa.docx
Paper OrganizationStart with a title page and organize your pa.docx
 
Paper on topic  Date visualization A critical evaluation of its ar.docx
Paper on topic  Date visualization A critical evaluation of its ar.docxPaper on topic  Date visualization A critical evaluation of its ar.docx
Paper on topic  Date visualization A critical evaluation of its ar.docx
 
PAPER EXPECTATIONSFollow the instructions.Make your ideas .docx
PAPER EXPECTATIONSFollow the instructions.Make your ideas .docxPAPER EXPECTATIONSFollow the instructions.Make your ideas .docx
PAPER EXPECTATIONSFollow the instructions.Make your ideas .docx
 
Paper Instructions 5) Paper should be 5-7 pages (excluding title pag.docx
Paper Instructions 5) Paper should be 5-7 pages (excluding title pag.docxPaper Instructions 5) Paper should be 5-7 pages (excluding title pag.docx
Paper Instructions 5) Paper should be 5-7 pages (excluding title pag.docx
 
Paper format and information4-5 pages in length.Papers mu.docx
Paper format and information4-5 pages in length.Papers mu.docxPaper format and information4-5 pages in length.Papers mu.docx
Paper format and information4-5 pages in length.Papers mu.docx
 
Paper in Health care quality management strategies - recent arti.docx
Paper in Health care quality management strategies - recent arti.docxPaper in Health care quality management strategies - recent arti.docx
Paper in Health care quality management strategies - recent arti.docx
 
Paper 2 Assignment POT 2002.Assignment Write a 1000 wor.docx
Paper 2 Assignment POT 2002.Assignment Write a 1000 wor.docxPaper 2 Assignment POT 2002.Assignment Write a 1000 wor.docx
Paper 2 Assignment POT 2002.Assignment Write a 1000 wor.docx
 
Paper detailsUnit 4 Discussion Prompt1. What is the .docx
Paper detailsUnit 4 Discussion Prompt1. What is the .docxPaper detailsUnit 4 Discussion Prompt1. What is the .docx
Paper detailsUnit 4 Discussion Prompt1. What is the .docx
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

1 Goals. 1. To use a text file for output and later for in.docx

  • 1. 1 Goals. 1. To use a text file for output and later for input. 2. To use exceptions and write an exception handler that does more than abort execution. 3. To Use a static class variable. 4. To use a boolean variable and a Date variable. 5. To use an ArrayList. 6. To implement Phase 1 of a four phase well-structured project with multiple classes using the Model-View-Controller design pattern (MVC). 2 Overview This section discusses a finished application that you will construct in several phases. When all phases are finished, it will simulate a human resources system to keep track of savings through the company. There is a Human Resources Manager (Boss), and employees (eventually more than one type of employee will be used). Eventually, this system will be created as an application with a windows interface. The Employee’s login name will eventually be encrypted and the data will be stored in an object file. Program 4 implements only part of the menu, uses a text file and does not encrypt the employee data. At first this will be a menu-driven application allowing for these actions: 1. The first time the program is used, the user will enter his or her own data in to the program and will become the Boss (Human Resources Manager) with access to everyone’s data. 2. After that, when the program starts up, it will read in a database of employee data and store it in the employee collection. 3. After that, the Boss will be able to log in and create new employees by entering the person’s name (first, middle initial-
  • 2. optional, and last), login name, base salary, and savings percent. This data will be used to initialize a new employee object. The object will also record the current date and a unique ID number for this employee. The new employee will be added to the Employee collection. 4. The Boss can log in and display a list of all Employees in the collection and can change the base salary or percent savings for any employee. In the list, display the full name (first, middle initial and last), login name, Employee ID, base salary, percent savings and date of hire for each Employee. 5. Any Employee in the collection can log in and see his or her own data and change their name and percent savings (due to marriage, etc). 6. An Employee whose login name is in the collection may log in and out. Logging in will automatically log out the prior Employee. 7. The menu has an option to quit and quitting will cause the final contents of the collection to be written back to the database file (replacing it). 8. Since you have more than one class in this project, you will need to create a package (call it “savings” – note the first letter is lower case) and put all of the classes in the package. To tell your program to look for the other classes, you need to put the following in each class file near your import statements. package savings; 3 The Employee Class: Superclass of the Model (from MVC) for this application. a) An object of type Employee will have the following data members: i) A
  • 3. static int variable called nextId. See the detailed instructions below. This is to make sure that the Employee ID is not re-used. There is one of these for the class and we use it to set the employee ID. ii) The Employee ID is a final int variable. It cannot be updated. In your output, it should be printed as a five digit number with leading zeros (use printf with the format “%05d” so it looks like this 00001). iii) The Employee’s name. When entered, it can include spaces and punctuation, and will be terminated by the end of line character. Store it as a single String. The name should be entered as Last name, first name and middle initial (optional). iv) Login name has no spaces and it can contain letters or numbers. It must be at least 6 characters long. For Program 5 you will have to make this unique in the database (no duplicates). When an employee logs-in they use this data member (we have not implemented password yet). v) The base salary (a double). vi) The percent savings (a double). vii) Date variable, set to the date that the employee was entered in to the system. viii) A boolean variable that is set to true, isEmployee. False means this employee is no longer an employee and should not be paid or be allowed to add to their company savings. b) Provide a constructor with four parameters (login, name, salary and percent savings) that initializes all Employee data members. c) Provide a constructor with all data members as parameters that reads the data from the file and adds an instance of the Employee class to the ArrayList or other collection and initializes all Employee data members.
  • 4. d) Do not implement get functions (accessors) for variables unless they are needed. You will need them at some point, but you may not need any accessors for P4. e) Implement a set function for the salary, percent savings and name. These are known as mutators. f) Implement a toString() function that will format the data members of Employee. Put each Employee on a single line of the output. Include the ID, login name, name, salary, percent savings, and date of hire separated by tab characters. 2) The Employee ID The employee ID number will be generated by the system, using the static class member Employee.nextId . The Boss will become employee ID 0. Each time an employee is created, the nextID must be copied in to that employee’s ID number, then nextId must be incremented. In this way no two employees can have the same ID. In your output and file, make this a system generated variable that is five digits long and starts with 00001 (00000 for the Boss) and goes up from there. An Employee ID number cannot be reused. 4 The main() function for P4: The main() function When the file is saved, the nextID number must be saved on the file first before the ArrayList data is saved. When the file is read, the value of the nextID number must be initialized (via the mutator function setId) to the saved value from the file. Main can be in a separate class called Main or it can be inside the Savings class. method should print a title line to the console showing the program name and your name. Then it should instantiate a Savings object and call the Savings object’s doMenu() function. When caught, print a comment, a stack trace, and abort.
  • 5. execution terminates for any reason, the data in the collection must be written back out to the file. This means you need a finally block following the main’s try block. Do the following: 1. First, reopen the input file for output. This will destroy the original contents of the file. 2. Then execute a “serialize” operation: write each object in the collection to the file using a loop. 3. Lastly, close the new database file. 5 The Savings Class for P4: the controller class (from MVC) of this application. a. The Savings class should contain an ArrayList of Employee, and variables to store the current Employee (a reference to an Employee in the ArrayList), a menu, a Scanner for the keyboard, a Scanner for the Employee-file, and a PrintWriter for the Employee file. b. You may use this to define the menu: private static String menu = “Savings System Menunt1. Log In n” + “ t2. Enter employees nt3. List employees” + “ nt4. Change employee data nt5. Terminate an employee” + nt6. Report employee savings nt0. Exit system” c. Use a switch statement to process the menu choices. Write a separate function for each option! They will be necessary when we convert the application to a GUI. d. In program 4, we will implement menu options 1, 2, and 0. 5.1 The Savings constructor. e. The first time this program is run, the file of Employee data
  • 6. (employee file) will not exist. On second and further runs, it will exist. The Exception system allows us to implement the right functionality using a try..catch. Enclose the file handling in a try block and write a catch block for FileNotFoundException . Note: an IOException should not happen because of the way you have set up your program to prevent it by checking the input data. If it does, let the exception pass up to main. You do not need to handle it here. The try block should do the following: i. Open the Employee file and a Scanner to read it. ii. Read all of the data one line at a time using a normal loop and hasNext(). Create a series of Employee objects and store them in the Employee collection (ArrayList). iii. Close the Scanner (which closes the input file). The catch block should do the following: iv. This is the handler for a FileNotFoundException, which will occur the first time this program is run and anytime you delete the data file. If the file exists (second and later execution), this error will not occur. v. Print a clear comment about the missing file. vi. Prompt the user for the logon name, salary, percent savings and name of the boss, create an Employee object with ID Number 0 and add it to the empty Program 4: Employee Savings Database CSCI 6617 Spring 2016 4 Employee collection (ArrayList). Then continue with normal execution of this application, DO NOT ABORT. f. At this point, the data from the file has been read, if it existed. The next step is to open an output file with the same name as the now-closed input file (replace it).
  • 7. i. Put this code in second a try block that immediately follows the catch block from the earlier try. ii. Control will come here after the first try-block or its catcher finishes its work. Notice that we are reentering execution after an exception. iii. At the end of the constructor, the program, its Employee ArrayList, and its output file are ready for use. 4.2 The doMenu() function Write a main loop that displays the menu forever (an infinite loop), until the user selects ”0. Exit System”. iv. Put the entire menu loop in a try block with a finally clause. 1. In the finally clause, write all of the Employees in the Employee ArrayList to the output file using a loop, close the file, and print a message on the console screen saying this was completed. 2. After the finally block, control should return to main, where it hits the end of another try block and ends the program. v. Prompt the user for a menu choice and process that choice with a switch. Do not use an if. . . else structure. 1. In the switch, do NOTHING except call one of the functions below. When the program is converted to Java FX, this switch will be replaced by a bunch of Buttons and other objects. 2. Break out of both the switch and the infinite loop if the user selects ”0. Exit System” . Leaving the loop will end the try block, which will send control directly to the finally block. 3. Create an empty method (stub) to process each of the following “3. List employees”, “ 4. Change employee data”, “5. Terminate employees” and “6. Pay employees” because these menu choices are not implemented in P4.
  • 8. Savings needs public functions for the menu options. i. The Savings class needs a private utility function, login() to implement ”1. Log In” . 4. login() prompts the user to enter their login name and checks the Employee ArrayList to see if they are an Employee (if that Login Name is in the collection). 5. If the user is not in the Employee collection, they cannot proceed. Print a message saying so and allow them to return to the menu. ii. newEmployee(): to create a new Employee member (about 20-30 lines of code, including whitespace and comments). This is run when there are no employees in the ArrayList or when “2 Enter Employees” is chosen by the Boss (when logged in Employee ID is 0). 6. Prompt for and read the Employee person's full name (assume that there is a first and last name, but make the middle initial optional. Allow for a hyphen in the last name), and the other data members (fields). 7. Create a new Employee with this data and put it into the ArrayList of Employees. Program 4: Employee Savings Database CSCI 6617 Spring 2016 5 iii. No function is needed for the ”0 Exit the System” menu item. Just break out of the loop. 8. Break out of both the switch and the infinite loop if the user selects ”0 Exit the System” . 9. Leaving the loop will end the try block, which will send control directly to the finally block.
  • 9. 6 Testing and Submission. Due by 11:59 PM on the due date. When you are sure your program works, delete the input and output files. Then follow the testing procedure below. 1. Start the program and enter your own name. Make up the data (name, logon name, salary and percent savings). Enter this user as the Boss. 2. Add a second user you made up. 3. Exit the system. 4. Make a copy of the database file and make its name run1.txt and copy and paste your console output to a file called console1.txt (you can use notepad to save this). 5. Start the program again. Enter two more users – make them up. This makes four users in total. 6. Exit the system. Use the two runs to test errors in entering the data. Finally, hand in a zipped folder containing: Employee classes and Main if you created one). and paste them in to the same file, but clearly mark them as run 1 and run 2 console output.