Question
Week 06 (for my use) Use Eclipse IDE for the exercises. Java programs to be used for these exercises. Employee.java public class Employee { private
Week 06 (for my use)
Use Eclipse IDE for the exercises.
Java programs to be used for these exercises.
Employee.java
public class Employee { private int staffID; // employee unique identifier private String firstName; private String surname; private String address; // home address private double annualLeave; // accrued annual leave available (hours) private double longServiceLeave; // accrued long service leave available (hours) // other data fields from lecture 4 not implemented in this example to keep it // brief
/** * @param ID - The new employees staff identification number */ public void setStaffID(int ID) { staffID = ID; }
/* * All other mutator methods should be defined here */
/** * @return staff Identification number */ public int getStaffID() { return staffID; }
/* * All other accessor methods should be defined here */
/** * Determines if the employee has sufficient accrued leave to cover the * requested number of hours of leave. * * @param leaveType type of leave requested. A = Annual, L = long service * @param requestedHours number of leave hours requested by employee * @return true if leave is approved, false otherwise */ public boolean hasEnoughLeave(String leaveType, float requestedHours) { if (leaveType.equalsIgnoreCase("A")) { if (annualLeave >= requestedHours) { return true; } else { return false; } } else { if (longServiceLeave >= requestedHours) { return true; } else { return false; } } }
} // end Employee class
employeeDemo.java
/** * Week 5 practical code. Not to be used without permission and appropriate * referencing */
public class employeeDemo { public static void main(String[] args) { /* * This program demonstrates the use of the Employee class and some of its * methods to learn about the use of accessors and mutators */
Employee accountant = new Employee();
System.out.println(" We just created the accountant object. Let's check the values of it's data fields."); System.out.println(" Initial values for accountant object data fields:"); System.out.println("Staff ID:\t\t\t" + accountant.getStaffID()); System.out.println("First Name:\t\t\t" + accountant.getFirstName()); System.out.println("Surname:\t\t\t" + accountant.getSurname()); System.out.printf("Annual Leave:\t\t\t%.2f", accountant.getAnnualLeave()); System.out.printf(" Long Service Leave:\t\t%.2f" , accountant.getLongServiceLeave()); System.out.println(" Home Address:\t\t\t" + accountant.getAddress());
} }
1. d
Add the following constructor to the Employee class:
/**
* No-Arg Constructor - create the new employee object with some default
* values. Note: these values are for the purpose of the example only and are
* not particularly sensible values to choose.
*/
public Employee() {
staffID = 99999;
firstName = "Eileen";
surname = "Over";
payRate = 16.75f; // the minimum payrate for an employee at the company
}
/**
* Constructor - create the new employee object using the values from the parameters as listed
*
* @param ID - The new employees staff ID.
* @param fName - The new employees first name
* @param sName - The new employees surname
* @param rate - The new employees hourly rate of pay
*/
public Employee(int ID, String fName, String sName, float rate) {
staffID = ID;
firstName = fName;
surname = sName;
payRate = rate;
}
Write a java program for 3.
1. a. This is a continuation of Exercise 1 from Week 5 practical exercises. Use the two java files, Employee.java and Employee Demo.java that you developed in Exercise 1 Week 5. Import the two java files into a new project in Eclipse then: Add the following data fields to the Employee class Department - the name of the department where the employee works [a string] Position - the employees job title (a string] Supervisor id - the staff id of the supervisor for the employee [an integer] Pay rate - the hourly pay rate for the employee (a float] Hours worked - the total hours worked by the employee in the current pay period (a float] Add accessor and mutator methods for these new data fields to the Employee class Implement input validation for pay rate and Hours Worked to ensure that negative values are not allowed. Should this be the responsibility of the Employee class or the main program? d. Add the following constructors to the Employee class b. C. /** * No-Arg Constructor - create the new employee object with some default * values. Note: these values are for the purpose of the example only and are * not particularly sensible values to choose. */ public Employee() { staffID = 99999; firstName = "Eileen"; surname = "Over"; payRate = 16.75f; // the minimum payrate for an employee at the company } * /** * Constructor - create the new employee object using the values from the parameters as listed * @param ID - The new employees staff ID. * @param fName - The new employees first name * @param sName - The new employees surname * @param rate - The new employees hourly rate of pay */ public Employee(int ID, String fName, String sName, float rate) { staffID = ID; firstName = f Name; surname = sName; payRate = rate; } e. f. g. Run the employee Demo code. Notice that the initial data field values for the accountant object are different from week 5. Why is this? Add a third constructor to the Employee class that takes as arguments values for all data fields In the employee Demo source code add Java code to do the following: i. Instantiate an Employee object, cleaner, using the four-argument constructor from part d above. To do this obtain the data for each of the data fields from the keyboard and then use these values as the arguments for the constructor. ii. Instantiate an Employee object, technician, using the constructor from part f above. To do this obtain the data for each of the data fields from the keyboard and then use these values as the arguments for the constructor iii. For the three objects (accountant, cleaner, technician) calculate and display the Gross Pay for the current pay period. Ensure that your code uses the validation that was implemented in part c. 3. Write a Movie class that stores the movie title, production company name, lead actor name, Australian classification rating, year released, and gross box-office takings. In the class also write appropriate constructor(s) and get and set methods. Write a separate main program that instantiates movie objects for each movie in a movie playlist or collection (for now, assume that the movie playlist/collection consists of only 3 movies). When instantiating movie objects, the data for each movie should be obtained from the user via the keyboard (note: in a future exercise this will be changed so that the movie data is obtained from an external file instead of the keyboard). Implement input validation of the year released (cannot be before 1920), the gross box-office takings (cannot be less than $0.00), and the Australian classification rating (must be one of G, PG, M, MA, R). After obtaining the data for the 3 movies display the data for each object in a summary table similar to the following: Title Year Released Rating Lead Actor Production Company Gross Box Office 2010 2003 1998 Inception Johnny English Saving Private Ryan M PG MA Leonardo Dicaprio Rowan Atkinson Tom Hanks Warner Bros. Universal Pictures Paramount Pictures $831500000 $160466000 $485035000
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started