REALLY NEED HELP WITH THIS JAVA ASSIGNMENT!! Objectives: The focus of this assig
ID: 3582214 • Letter: R
Question
REALLY NEED HELP WITH THIS JAVA ASSIGNMENT!!
Objectives: The focus of this assignment is the use Swing components to create a simple GUI based program
Program Description:
The final portion of the project will be to create a GUI interface for the user, getting rid of the text-based menu system. The application will use the EmployeeManager in the same way the EmployeeDriver did, but provide an easier interface.
A total of fifteen classes are required.
EmployeeFrame – Java Swing Frame (starter code provided)
EmployeeFrameDriver - Provided
Queue – (From previous assignment)
ListNode – (From previous assignment)
LikedList – Implementation of the LinkedList data structure of Comparables
EmptyListException – (From previous assignment)
ArrayList (From previous assignment)
InvalidEmployeeNumberException (From previous assignment)
InvalidSizeException (From previous assignment)
MaximumCapacityException (From previous assignment)
Employee (Altered from previous assignment)
HourlyEmployee (From previous assignment)
SalaryEmployee (From previous assignment)
CommissionEmployee (From previous assignment)
EmployeeManager (Altered from previous assignment)
The final result will look something like this:
We will no longer be outputting to the console through System.out, rather a JTextArea is provided for satisfying output requests and messages. This will in effect be our new “console”. In order to take advantage of this, there are some small changes that need to be made to the EmployeeManager. Some of the EmployeeManager’s methods output directly to System.out, we do not want that any more since all output should be in the JTextArea for the user.
Changes to EmployeeManager
Changes for removing System.out output
EmployeeManager
- employees : ArrayList<Employee>
- employeeMax : final int = 10
- hourlyList : LinkedList<Employee>
- salaryList : LinkedList<Employee>
- commissionList : LinkedList<Employee>
- vacationRequests : Queue<Employee>
<<constructor>> EmployeeManager()
+ addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double) throws InvalidEmployeeNumberException
+ removeEmployee( index : int)
+ listAll() : String
+ listHourly() : String
+ listSalary() : String
+ listCommision() :String
+ resetWeek()
+ calculatePayout() : double
+ getIndex( empNum : int ) : int
+ annualRaises()
+ holidayBonuses() : double
+ increaseHours( index : int, amount : double) : boolean
+ increaseSales( index : int, amount : double) : boolean
+ findAllBySubstring(find : String) : Employee[]
- RabinKarp(name : String, find : String) : int
- stringHash(s : String) : int
- charNumericValue(c : char) : int
- RabinKarpHashes(s : String, hashes : int[], pos : int, length : int) : int
- linearSearchRecursive(nameHashes : int[], findHash : int, pos : int) : int
+ sort()
+ addRequest(empNum : int) : boolean
+ viewNextRequest() : Employee
+ grantNextRequest() : Employee
+ outputRequests() : String
+ loadEmployees(employeeFile : String, requestFile : String) boolean
+saveEmployees(employeeFile : String, requestFile : String) boolean
+processUpdates(fileName : String) boolean
Changes detailed on following page
list methods
Instead of outputting the toString of the ArrayList and LinkedLists in the methods, the String is now returned. If there are no Employees listAll() will return the String, “No Employees”. If there are no Employees of a specific type, its cooresponding list method will return a String indicating that, for example, “No Hourly Employees”.
public double holidayBonuses()
This will still return the total of all bonuses, but remove the output of the individual bonuses in the method.
public boolean increaseHours/Sales()
Both of these methods will return a true if they are successful, false if they are not. Remove output to System.out.
public String outputRequests()
Similar change as the list methods. Returns the String of requests. If there are no requests returns the String “No vacation requests”.
EmployeeFrame
EmployeeFrame extends JFrame
em : EmployeeManager
employeeTypeCombo : JComboBox<String>
firstField : JTextField
lastField : JTextField
middleCombo : JComboBox<Character>
genderCombo : JComboBox<Character>
employeeNumberField : JTextField
fullTimeRadio : JRadioButton
partTimeRadio : JRadioButton
amountField : JTextField
addEmployeeButton : JButton
employeeNumberRemoveField : JTextField
removeButton : JButton
employeeNumberUpdateField : JTextField
amountUpdateField : JTextField
updateHourlyButton : JButton
updateCommissionButton : JButton
updateFromFileButton : JButton
payoutButton : JButton
bonusButton : JButton
raisesButton : JButton
resetWeekButton : JButton
viewRequestButton : JButton
addRequestButton : JButton
grantRequestButton : JButton
sortPrintButton : JButton
printHourlyButton : JButton
printSalaryButton : JButton
printCommissionButton : JButton
findButton : JButton
exitButton : JButton
console : JTextArea
<<constructor>> EmployeeFrame()
createMiddleOptions() : Character[]
The EmployeeFrame has the following private inner class. This inner class will be the Event Handler for all of the EmployeeFrame’s buttons. Only the JButtons of the EmployeeFrame need a listener, no other components have a listener.
ButtonHandler implements ActionListener
+ actionPerformed(event : ActionEvent)
Starter code has been provided. This declares all of the data members, gives you the createMiddleOptions method (Used to quickly create an array of Characters A-Z for the middle initial Combo Box, and the set up of the JTextArea console.
Constructor
Sets up the Frame and creates all components. Creates the EmployeManager object the application will be manipulating. As you can see above, the Frame is logically split up into sections using panels. For each of these sections create a JPanel, set its Layout to a Flow Layout and give it a black boarder. This can be done like this:
JPanel addPanel = new JPanel();
addPanel.setLayout(new FlowLayout());
addPanel.setBorder(BorderFactory.createLineBorder(Color.black));
Then create all of the components for that panel and add them to the panel in the order in which they appear, then add the panel to the Frame. Get your application to look as close to the example as possible noting the following JTextField sizes below as well as the default text.
JTextField Sizes
Name fields: 15
Employee Number fields: 5
Amount fields: 10
The Full/Part JRadioButtons belong to a ButtonGroup to ensure only one is selected at one time.
Also note that each section has a JLabel as the first component, do not forget to create and add these as well. They are not class wide data members since they do not need to be further referenced by us. We need access to the other components in the handler, so those are class wide.
Once all of the components have been created and added, attempt to call upon the EmployeeManager’s loadEmployees with the file name, “employees.ser” and “requests.dat”. If successful output “Employees Loaded” to the console, otherwise “Employees Not Loaded”
Notes on JTextArea console
Whenever you perform an action that causes the console to be updated clear the previous contents to avoid clutter. These two JTextArea methods will be helpful for manipulating the console:
public void setText(String t)
Sets the text of the JTextArea to the passed String, removing the current contents.
Public void append(String t)
Appends the passed String to the current contents of the JTextArea.
ButtonHandler
Your EmployeeFrame constructor only needs to create ONE instance of the ButtonHandler, since the same Handler will be capable of handling all buttons. Add the same handler to all JButton components.
Note on input components
Some of the operations require altering the contents of one or more of the JTextFields, JComboBoxes, and/or JRadioButtons. Once the action has occurred reset the associated components to their starting values. For example, the user enters all of the information for a new Employee and hits the “Add Employee” button. Whether or not it was successful set all of the components back. firstField is set back to the String, “First”, lastField to, “Last”, middleCombo to ‘A’, genderCombo to ‘M’, etc.
Following is what should happen if the JButtons are pressed. These actions go in the ButtonHandler’s actionPerformed() method as demonstrated in class. First determine which button triggered the event by using the event’s getSource() method, then perform the correct actions for that button.
addEmployeeButton
Using the user inputs from the Add Employee section, call upon the EmployeeManager’s addEmployee. If the Employee is added successfully output “Employee Added” to the console. If either an InvalidEmployeeNumberException or NumberFormatException occurs output “Invalid Employee Number to the console. Reset the user inputs back to defaults.
removeButton
Attempt to remove the Employee given in the section. If successful output, “Employee (EmployeeNumber) Removed”. If the Employee does not exist or a NumberFormatException occurs output “No Such Employee”. Reset the Employee number field.
updateHourlyButton/updateCommissionButton
Using the values in the Employee number and amount field attempt to call upon the increaseHours/increaseSales method. If a NumberFormatException occurs in parsing the Employee number or amount output “Invalid Employee Number” or “Invalid Amount”, respectively. If the Employee does not exist output “No Such Employee”. If the call to increaseHours/increaseSales returns false, this means the index passed is not to the correct type of Employee, output that information to the console as either, “Employee Not Hourly” or “Employee Not Commission”, respectively.
If the action is successful output one of the following depending on the button pressed, “(Employee Number) increased by (Amount) hours” or “(Employee Number) increased by (Amount) sales”. The amount should be formatted to show exactly 2 decimal points.
updateFromFileButton
To choose the file to use we will use the JFileChooser, the majority of the code is provided here:
JFileChooser fileChooser = new JFileChooser(new File("."));
int fileRet = fileChooser.showOpenDialog(null);
if(fileRet == JFileChooser.APPROVE_OPTION)
{
if(em.processUpdates(fileChooser.getSelectedFile().getAbsolutePath()))
{
//Output "Updates Processed Successfully" to console
}
else
{
//Output "Updates Not Processed" to console
}
}
payoutButton
Using EmployeeManager’s calculatePayout() output the payout to the console in the format, “Total weekly payout is (Amount)”
bonusButton
Using EmployeeManager’s holidayBonuses() output the bonus amount to the console in the format, “Total holiday bonus is (Amount)”
raisesButton
Applies the EmployeeManager’s annualRaises() and outputs “Annual Raises Applied”.
resetWeekButton
Applies the EmployeeManager’s resetWeek() and outputs “Weekly values reset”.
viewRequestButton
Outputs the String returned by EmployeeManager’s outputRequests to the console. If there is a non-null Next Request output it to the console as well in the format, “(Employee) will receive next request”
addRequestButton
Prompt user for an Employee number using JOptionPane’s showInputDialog with the text “Enter Employee Number”
Attempts to add Employee with the given number to the vacation Queue. If a NumberFormatException occurs when parsing the input output “Invalid Employee Number to the console. If the Employee does not exist output “No Such Employee” to the console. If the action is successful output “Employee (Employee Number) added to vacation queue” to the console.
grantRequestButton
Attempt to grant next vacation request. If there is no Employee in the Queue output “No vacation requests” to console, if it succeeds output “(Employee) granted vacation request”
sortPrintButton
Sort the Employees using the EmployeeManager’s sort() then output all Employees to the console.
printHourlyButton/printSalaryButton/printCommissionButton
Output the appropriate Employees to the console.
findButton
Prompt user for a search String using JOptionPane’s showInputDialog with the text “Enter Search String”
If nothing is entered do not try to search. If a String is entered us EmployeeManager’s findAllBySubstring() to output matches to the console. If an InvalidCharacterException is thrown output “Invalid character found in search” to the console.
exitButton
Call EmployeeManager’s saveEmployees with the files “employees.ser” and “requests.dat” and terminate the program by calling System.exit(0)
Testing
All functionality will be retested for the final version of the project, so if you did not fix problems from previous iterations be sure to update them. Testing will basically be the same as previous versions, the only differences being the way input is done through the GUI and output goes to the JTextField.
Other Notes:
Import classes to files as necessary
Be sure to format your output to the console as it is described in this document
Format all amounts to exactly 2 decimal places
Each action should clear the previous contents of the console before performing its own output
The only way the current data is saved is by hitting the “Save/Exit” button. If in testing you made changes to the Employees that you DO NOT want to save, closing the application with the red X will exit without saving
EmployeeManager
- employees : ArrayList<Employee>
- employeeMax : final int = 10
- hourlyList : LinkedList<Employee>
- salaryList : LinkedList<Employee>
- commissionList : LinkedList<Employee>
- vacationRequests : Queue<Employee>
<<constructor>> EmployeeManager()
+ addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double) throws InvalidEmployeeNumberException
+ removeEmployee( index : int)
+ listAll() : String
+ listHourly() : String
+ listSalary() : String
+ listCommision() :String
+ resetWeek()
+ calculatePayout() : double
+ getIndex( empNum : int ) : int
+ annualRaises()
+ holidayBonuses() : double
+ increaseHours( index : int, amount : double) : boolean
+ increaseSales( index : int, amount : double) : boolean
+ findAllBySubstring(find : String) : Employee[]
- RabinKarp(name : String, find : String) : int
- stringHash(s : String) : int
- charNumericValue(c : char) : int
- RabinKarpHashes(s : String, hashes : int[], pos : int, length : int) : int
- linearSearchRecursive(nameHashes : int[], findHash : int, pos : int) : int
+ sort()
+ addRequest(empNum : int) : boolean
+ viewNextRequest() : Employee
+ grantNextRequest() : Employee
+ outputRequests() : String
+ loadEmployees(employeeFile : String, requestFile : String) boolean
+saveEmployees(employeeFile : String, requestFile : String) boolean
+processUpdates(fileName : String) boolean
Explanation / Answer
EmployeeManager.java
import employeeType.subTypes.HourlyEmployee;
import employeeType.subTypes.SalaryEmployee;
import employeeType.subTypes.CommissionEmployee;
import employeeType.employee.Employee;
import dataStructures.ArrayList;
import dataStructures.LinkedList;
import dataStructures.Queue;
import exceptions.InvalidCharacterException;
import exceptions.InvalidEmployeeNumberException;
import exceptions.InvalidSizeException;
import exceptions.MaximumCapacityException;
import exceptions.EmptyListException;
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.lang.SecurityException;
import java.util.NoSuchElementException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Formatter;
import java.util.FormatterClosedException;
@SuppressWarnings("unchecked")
public class EmployeeManager
{
private ArrayList<Employee> employees;
private final int employeeMax = 10;
private LinkedList<Employee> hourlyList;
private LinkedList<Employee> salaryList;
private LinkedList<Employee> commissionList;
private Queue<Employee> vacationRequests;
public EmployeeManager()
{
try
{
employees = new ArrayList<Employee>(3);
}
catch (InvalidSizeException E)
{
try
{
employees = new ArrayList<Employee>(employeeMax);
}
catch (InvalidSizeException e)
{
}
}
hourlyList = new LinkedList();
salaryList = new LinkedList();
commissionList = new LinkedList();
vacationRequests = new Queue();
}
public void addEmployee(int type, String fn, String ln, char m, char g, int en, boolean ft, double amount) throws InvalidEmployeeNumberException
{
if (type == 1)
{
HourlyEmployee E = new HourlyEmployee (fn,ln,m,g,en,ft,amount);
try
{
employees.addItem(E);
hourlyList.insertAtBack(E);
}
catch (MaximumCapacityException e)
{
System.out.print("too large");
}
}
if (type == 2)
{
SalaryEmployee E = new SalaryEmployee (fn,ln,m,g,en,ft,amount);
try
{
employees.addItem(E);
salaryList.insertAtBack(E);
}
catch (MaximumCapacityException e)
{
System.out.print("too large");
}
}
if (type == 3)
{
CommissionEmployee E = new CommissionEmployee (fn,ln,m,g,en,ft,amount);
try
{
employees.addItem(E);
commissionList.insertAtBack(E);
}
catch (MaximumCapacityException e)
{
System.out.print("too large");
}
}
}
public void removeEmployee(int index)
{
if(index != -1)
employees.removeItem(index);
}
public String listAll()
{
String x = "";
if(employees.isEmpty() == true)
return "No Employees";
else
return x + employees.toString();
}
public String listHourly()
{
String a = "";
for (int x = 0; x < hourlyList.lengthIs(); x++)
{
if (hourlyList.isEmpty() == true)
return "No Hourly Employees";
else if (hourlyList.getItem(x) instanceof HourlyEmployee)
{
return a + hourlyList.toString() + " ";
}
}
}
// Method: listSalary
public String listSalary()
{
String b = "";
for (int x = 0; x < salaryList.lengthIs(); x++)
{
if(salaryList.isEmpty() == true)
{
return "No Salary Employees";
}
else if (salaryList.getItem(x) instanceof SalaryEmployee)
{
return b + salaryList.toString() + " ";
}
}
}
public String listCommission()
{
String c = "";
for (int x = 0; x < commissionList.lengthIs(); x++)
{
if(commissionList.isEmpty() == true)
{
return "No Commission Employees";
}
else if (commissionList.getItem(x) instanceof CommissionEmployee)
{
return c + commissionList.toString() + " ";
}
}
}
public void resetWeek()
{
for (int a = 0; a < employees.lengthIs(); a++)
{
employees.getItem(a).resetWeek();
}
}
public double calculatePayout()
{
double payout = 0;
for (int a= 0; a < employees.lengthIs(); a++)
{
payout += employees.getItem(a).calculateWeeklyPay();
}
return payout;
}
public int getIndex(int empNum)
{
for (int a = 0; a < employees.lengthIs(); a++)
if (empNum == employees.getItem(a).getEmployeeNumber())
return a;
return -1;
}
public void annualRaises()
{
for (int a = 0; a < employees.lengthIs(); a++)
{
employees.getItem(a).annualRaise();
}
}
public double holidayBonuses()
{
double payout = 0;
for (int a = 0; a < employees.lengthIs(); a++)
{
payout += employees.getItem(a).holidayBonus();
//System.out.print (employees.getItem(a).toString());
double b = employees.getItem(a).holidayBonus();
System.out.printf ("Bonus ammount: %.2f", b);
System.out.print (" ");
}
return payout;
}
public boolean increaseHours(int index, double amount)
{
for (int x = 0; x < employees.lengthIs(); x++)
{
if (employees.getItem(x) instanceof HourlyEmployee)
{
if (index == ((HourlyEmployee)employees.getItem(x)).getEmployeeNumber())
{
((HourlyEmployee)employees.getItem(x)).increaseHours(amount);
}
else
return false;
}
}
return true;
}
public boolean increaseSales(int index, double amount)
{
for (int x = 0; x < employees.lengthIs(); x++ )
{
if (employees.getItem(x) instanceof CommissionEmployee)
{
if (index == ( ((CommissionEmployee)employees.getItem(x)).getEmployeeNumber()))
{
((CommissionEmployee)employees.getItem(x)).increaseSales(amount);
}
else
return false;
}
}
return true;
}
public ArrayList<Employee> findAllBySubstring(String find)
{
ArrayList<Employee> ken = new ArrayList();
int count = 0;
for (int a = 0; a < employees.lengthIs(); a++)
{
if((RabinKarp((employees.getItem(a).getFirstName() + employees.getItem(a).getLastName()), find)) != -1)
{
try
{
ken.addItem(employees.getItem(a));
}
catch (MaximumCapacityException e)
{
System.out.print("too large");
}
}
}
return ken;
}
private int RabinKarp(String name, String find)
{
if (find.length() > name.length())
return -1;
int findHash = stringHash(find);
int [] nameHash = new int [name.length() - find.length() + 1];
String sub = name.substring(0, find.length());
nameHash[0] = stringHash(sub);
RabinKarpHashes(name, nameHash, name.length() - find.length(), find.length());
int x = linearSearchRecursive(nameHash, findHash, name.length() - find.length());
return x;
}
private int stringHash (String s)
{
int hash = 0;
for(int i = 0; i < s.length(); i++)
{
hash += charNumericValue(s.charAt(i))*Math.pow(26,s.length()-i-1);
}
return hash;
}
private int charNumericValue(char c) throws InvalidCharacterException
{
switch (c)
{
case 'a': case 'A':
return 0;
case 'b': case 'B':
return 1;
case 'c': case 'C':
return 2;
case 'd': case 'D':
return 3;
case 'e': case 'E':
return 4;
case 'f': case 'F':
return 5;
case 'g': case 'G':
return 6;
case 'h': case 'H':
return 7;
case 'i': case 'I':
return 8;
case 'j': case 'J':
return 9;
case 'k': case 'K':
return 10;
case 'l': case 'L':
return 11;
case 'm': case 'M':
return 12;
case 'n': case 'N':
return 13;
case 'o': case 'O':
return 14;
case 'p': case 'P':
return 15;
case 'q': case 'Q':
return 16;
case 'r': case 'R':
return 17;
case 's': case 'S':
return 18;
case 't': case 'T':
return 19;
case 'u': case 'U':
return 20;
case 'v': case 'V':
return 21;
case 'w': case 'W':
return 22;
case 'x': case 'X':
return 23;
case 'y': case 'Y':
return 24;
case 'z': case 'Z':
return 25;
}
throw new InvalidCharacterException(c);
}
private int RabinKarpHashes (String s, int[] hashes, int pos, int length)
{
if (pos == 0)
{
hashes[pos] = stringHash(s.substring(pos, pos + length));
}
if (pos > 0)
{
hashes[pos] = 26 * (RabinKarpHashes (s,hashes,pos-1, length) - (charNumericValue (s.charAt(pos-1)) * (int)Math.pow(26,length-1))) + charNumericValue(s.charAt(pos+length-1));
}
return hashes[pos];
}
private int linearSearchRecursive(int[] data, int key, int pos)
{
if (pos < 0)
{
return -1;
}
if (key == data[pos])
{
return pos;
}
return linearSearchRecursive(data, key, pos-1);
}
public void sort()
{
hourlyList.sort();
salaryList.sort();
commissionList.sort();
}
public boolean addRequest(int empNum)
{
if (empNum >= 10000 && empNum <= 99999)
{
vacationRequests.enqueue(employees.getItem(getIndex(empNum)));
return true;
}
else
return false;
}
public Employee viewNextRequest()
{
Employee emu = null;
if (vacationRequests == null)
return null;
else
return emu;
}
public Employee grantNextRequest()
{
if (vacationRequests != null)
{
return vacationRequests.dequeue();
}
else
return null;
}
public String outputRequests()
{
String o = "";
if (vacationRequests != null)
return o + vacationRequests.toString();
else
return "No vacation requests";
}
public boolean loadEmployees(String employeeFile, String requestFile)
{
FileInputStream file, file1;
ObjectInputStream inout = null ;
Scanner in;
Employee ee = null;
Queue<Employee> q = null;
int emp = 0;
////clear
System.out.print(hourlyList.toString());
employees.clear();
hourlyList.clear();
salaryList.clear();
commissionList.clear();
vacationRequests.clear();
/////ending clear
////employee
try
{
inout = new ObjectInputStream(new FileInputStream(employeeFile));
}
catch (FileNotFoundException fnfe)
{
System.out.println("Error");
}
catch (IOException ioe)
{
System.err.println("etr");
}
if (inout == null)
{
return false;
}
try
{
while(true)
{
try
{
ee = (Employee)inout.readObject();
employees.addItem(ee);
}
catch (NoSuchElementException nsee)
{
break;
}
catch (IOException a)
{
System.err.println("");
return true;
}
}
}
catch (MaximumCapacityException mce)
{
System.out.print("Maximum Capacity Reached");
return true;
}
catch (ClassNotFoundException cnfe)
{
System.out.print("err");
}
//
try
{
file = new FileInputStream(employeeFile);
}
catch (IOException a)
{
System.err.println("err");
return false;
}
//
try
{
if (file != null)
{
file.close();
}
}
catch (IOException IOE)
{
System.err.println("error closing file");
System.exit(1);
}
////queue
try
{
in = new Scanner(new File(requestFile));
}
catch (FileNotFoundException fnfe)
{
System.err.println("err");
return false;
}
while (true)
{
try
{
emp = in.nextInt();
}
catch (NoSuchElementException nsee)
{
break;
}
}
//
try
{
file1 = new FileInputStream(requestFile);
}
catch (IOException ioe)
{
System.out.print("err");
return false;
}
try
{
if (file1 != null)
{
file1.close();
}
}
catch (IOException ioe)
{
System.out.print("err");
System.exit(1);
}
return true;
}
// Method saves employees
public boolean saveEmployees(String employeeFile, String requestFile)
{
ObjectOutputStream output;
Formatter put = null;
Queue<Employee> vacayCopy = new Queue();
vacayCopy = vacationRequests;
////employeefile
try
{
output = new ObjectOutputStream(new FileOutputStream(employeeFile));
}
catch (IOException a)
{
System.out.println("error");
System.exit(1);
return false;
}
for (int x = 0; x < employees.lengthIs(); x++)
{
try
{
output.writeObject(employees.getItem(x));
}
catch (IOException a)
{
System.out.print("Error");
return false;
}
}
try
{
if(output != null)
{
output.close();
}
}
catch (IOException a)
{
System.out.println("error");
System.exit(1);
return false;
}
////requestfile
try
{
put = new Formatter(requestFile);
for (int x = 0; x < vacationRequests.lengthIs(); x++)
{
put.format("%d", vacationRequests.dequeue().getEmployeeNumber());
}
}
catch (FormatterClosedException fce)
{
System.out.println("error");
return false;
}
catch (FileNotFoundException fnfee)
{
System.out.print("err");
}
if (put != null)
{
put.close();
}
return true;
}
public boolean processUpdates(String fileName)
{
int emp = 0;
double requesT = 0.0;
Scanner input;
try
{
input = new Scanner(new File(fileName));
}
catch (FileNotFoundException fnfe)
{
System.out.print("Error, file not found");
System.exit(1);
return false;
}
while (true)
{
try
{
emp = input.nextInt();
requesT = input.nextDouble();
}
catch(NoSuchElementException nsee)
{
break;
}
int temp;
temp = getIndex(emp);
if (employees.getItem(temp) instanceof HourlyEmployee)
{
increaseHours(emp, requesT);
}
if (employees.getItem(emp) instanceof SalaryEmployee)
{
System.out.print("Cannot process update.");
}
if (employees.getItem(emp) instanceof CommissionEmployee)
{
increaseSales(emp,requesT);
}
if (temp == -1)
{
System.out.printf("Cannot process update %d is an invalid employee number.", emp);
}
}
if (input != null)
{
input.close();
}
return true;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.