CIT130 Extra Credit OOP Assignment UML Diagrams, Classes and Objects Video Explanation / Instructions / Demo: https://ww
Posted: Sat May 14, 2022 8:40 pm
CIT130 Extra Credit OOP Assignment UML Diagrams, Classes and Objects Video Explanation / Instructions / Demo: Please remember, it is important that you start as early as possible and ask questions. If you prefer to use the this.reference instead of the variable names provided you may do so Due Date: 05/08 (End of semester) (Sunday 11:59 PM) Your name and Lab assignment number must be included at the top of the Java source file in comments. For this assignment you will create & submit 2 classes: 1. Employee 2. Employee Demo Begin by creating a class named Employee (Do NOT include your last name, this will make creating objects based on the class more confusing) (This class will not have a main method) Below is the UML diagram for the class. Employee You may use this.private= public if you prefer (For constructors & setters) - name : String - salary: double - yearsWith : int - sales : double + Employee String n, double sala, int y, double sale ) + getName(): String - setSalary ( double s) : void - setYearsWith(int yw ): void - setSales ( double s) : void + promote(): boolean + calculate Raisel): double + toString(): String In the Employee class: Data fields: name, is a global (instance) variable of type String • salary, is a global instance) variable of type double • yearsWith, is a global (instance) variable of type int • sales, is a global (instance) variable of type double Continued on next page ... CIT130 Constructor: There is no default constructor for this class The constructor will take the arguments from the UML presented on page 1 o String, double, int, double For name - Use the "private = public" For all other variables, call the appropriate setter method passing the public variable
CIT130 . . Constructor: There is no default constructor for this class The constructor will take the arguments from the UML presented on page 1 o String, double, int, double For name - Use the "private = public" For all other variables, call the appropriate setter method passing the public variable . . Methods: Remember, refer to the UML diagram for arguments, public/private and return types getName() Simply returns the private name variable. .setSalary() o IF the variable the user provided is less than 0 assign salary to be 0 and print an error message. Otherwise private = public. Return the appropriate variable. • setYearsWith() o If the variable the user provided is less than 0 assign yearsWith to be 0 and print an error message. Otherwise private = public. Return the appropriate variable. setSales () o If the variable the user provided is less than 0 assign sales to be 0 and print an error message. Otherwise private = public. Return the appropriate variable. • promote() o If the users sales are greater than 9999 and they have been with the company for longer than 2 (at least 3) years, then the employee is eligible for a promotion. calculate Raise () o Assign the salary variable to equal itself plus 5%. Return the new salary. • toString() o Returns a neatly formatted String as seen in the images on the next page, referencing variables and method calls as needed.
CIT130 In the Employee Demo class: (This class WILL contain a main) 1. Create the following variables: A. Scanner Object B. Employee Array Hint: Employees() employee C. int (size) D. String (name) E. double (salary) F. int (years) G. double (sales) 2. Prompt the user for the number of employees to enter. Use a validation loop to ensure positive numbers. 3. Assign your Employee array to a new Employee object based on the given size 4. Use a for loop to iterate through the size of the array and: A. Clear the buffer (if needed) B. Prompt the user to enter the name of the employee C. Prompt the user to enter the salary of the employee D. Prompt the user to enter the years with the company of the employee E. Prompt the user to enter the sales of the employee F. Create a new Employee object at position i passing the variables above as arguments to the constructor 5. Use another for loop (or enhanced) to iterate through the Employee array and print each induvial Employees to String() method. 6. Print a message to the screen that states you will now show all employees eligible for promotion / raise & use a for loop to determine & print this information as shown in the image. Hints: A. An employee is eligible for promotion if the promote method returns true .. B. If you are having trouble accessing the employee's names, remember getName() is a public method C. The method that calculates the raise is also public! Continued on next page...
CIT130 Example of programming running ... Feel free to get creative. You do not have to have the EXACT output as shown. Validate size is >0 Enter the number of employees to poll: 0 Enter the number of employees to poll: -1 Enter the number of employees to poll: 4 Prompt for each variable for ith Employee object Loading Employees .. Enter employees first name: A Enter employees current salary: 50000 Enter employees years with the company: 10 Enter employees sales: 10000 Enter employees first name: B Enter employees current salary: 50000 Enter employees years with the company: 1 Enter employees sales: 10000 Enter employees first name: C Enter employees current salary: 50000 Enter employees years with the company: 10 Enter employees sales: 100 Enter employees first name: D Enter employees current salary: 10000 Enter employees years with the company: 3 Enter employees sales: 20000 Output data for each Employee object. Employee Information: Employee Name: A, has a current salary of $50000.o. Has been with the company for 10 years and last year old a total of $10000.0 Promption status = true Employee Name: B, has a current salary of $50000.o. Has been with the company for 1 years and last year sold a total of $10000.0 Promption status = false Employee Name: C, has a current salary of $50000.0. Has been with the company for 10 years and last year sold a total of $100.0 Promption status - false Print only employees who will receive a raise, and their new calculated salary Employee Name: D, has a current salary of $10000.0. Has been with the company for 3 years and last year sold a total of $20000.0 Promption status = true *** And now for the promotions! *** A salary increased to 52500.0 D salary increased to 10500.0 Enter employees first name: A Invalid Data Results Enter employees current salary: -999 Enter employees years with the company: -999 Enter employees sales: -999 If you have any questions, please ask for a demonstration of the program executing. Invalid SALARY entered. Setting to 0. Invalid YEARS with comapny entered. Setting to 0. Invalid SALES entered. Setting to so.
CIT130 . . Constructor: There is no default constructor for this class The constructor will take the arguments from the UML presented on page 1 o String, double, int, double For name - Use the "private = public" For all other variables, call the appropriate setter method passing the public variable . . Methods: Remember, refer to the UML diagram for arguments, public/private and return types getName() Simply returns the private name variable. .setSalary() o IF the variable the user provided is less than 0 assign salary to be 0 and print an error message. Otherwise private = public. Return the appropriate variable. • setYearsWith() o If the variable the user provided is less than 0 assign yearsWith to be 0 and print an error message. Otherwise private = public. Return the appropriate variable. setSales () o If the variable the user provided is less than 0 assign sales to be 0 and print an error message. Otherwise private = public. Return the appropriate variable. • promote() o If the users sales are greater than 9999 and they have been with the company for longer than 2 (at least 3) years, then the employee is eligible for a promotion. calculate Raise () o Assign the salary variable to equal itself plus 5%. Return the new salary. • toString() o Returns a neatly formatted String as seen in the images on the next page, referencing variables and method calls as needed.
CIT130 In the Employee Demo class: (This class WILL contain a main) 1. Create the following variables: A. Scanner Object B. Employee Array Hint: Employees() employee C. int (size) D. String (name) E. double (salary) F. int (years) G. double (sales) 2. Prompt the user for the number of employees to enter. Use a validation loop to ensure positive numbers. 3. Assign your Employee array to a new Employee object based on the given size 4. Use a for loop to iterate through the size of the array and: A. Clear the buffer (if needed) B. Prompt the user to enter the name of the employee C. Prompt the user to enter the salary of the employee D. Prompt the user to enter the years with the company of the employee E. Prompt the user to enter the sales of the employee F. Create a new Employee object at position i passing the variables above as arguments to the constructor 5. Use another for loop (or enhanced) to iterate through the Employee array and print each induvial Employees to String() method. 6. Print a message to the screen that states you will now show all employees eligible for promotion / raise & use a for loop to determine & print this information as shown in the image. Hints: A. An employee is eligible for promotion if the promote method returns true .. B. If you are having trouble accessing the employee's names, remember getName() is a public method C. The method that calculates the raise is also public! Continued on next page...
CIT130 Example of programming running ... Feel free to get creative. You do not have to have the EXACT output as shown. Validate size is >0 Enter the number of employees to poll: 0 Enter the number of employees to poll: -1 Enter the number of employees to poll: 4 Prompt for each variable for ith Employee object Loading Employees .. Enter employees first name: A Enter employees current salary: 50000 Enter employees years with the company: 10 Enter employees sales: 10000 Enter employees first name: B Enter employees current salary: 50000 Enter employees years with the company: 1 Enter employees sales: 10000 Enter employees first name: C Enter employees current salary: 50000 Enter employees years with the company: 10 Enter employees sales: 100 Enter employees first name: D Enter employees current salary: 10000 Enter employees years with the company: 3 Enter employees sales: 20000 Output data for each Employee object. Employee Information: Employee Name: A, has a current salary of $50000.o. Has been with the company for 10 years and last year old a total of $10000.0 Promption status = true Employee Name: B, has a current salary of $50000.o. Has been with the company for 1 years and last year sold a total of $10000.0 Promption status = false Employee Name: C, has a current salary of $50000.0. Has been with the company for 10 years and last year sold a total of $100.0 Promption status - false Print only employees who will receive a raise, and their new calculated salary Employee Name: D, has a current salary of $10000.0. Has been with the company for 3 years and last year sold a total of $20000.0 Promption status = true *** And now for the promotions! *** A salary increased to 52500.0 D salary increased to 10500.0 Enter employees first name: A Invalid Data Results Enter employees current salary: -999 Enter employees years with the company: -999 Enter employees sales: -999 If you have any questions, please ask for a demonstration of the program executing. Invalid SALARY entered. Setting to 0. Invalid YEARS with comapny entered. Setting to 0. Invalid SALES entered. Setting to so.