Question
must be written in JAVA: Instead of pseudocode for this program prepare a UML diagram. Use Word, Powerpoint, notepad for the UML OR put it
must be written in JAVA:
Instead of pseudocode for this program prepare a UML diagram. Use Word, Powerpoint, notepad for the UML OR put it in comments at the top of your java code.
Object Based Programming
Program #1: Employee class and program utilizing the Employee class
Write a class named Employee that has the following attributes (fields):
- name: The name attribute should be a String that holds an employees first and last name
- idNumber: The idNumber attribute is a String that holds an employees ID number
- department: The department attribute is a String that holds the name of the employees department that they work in
- position: The position attribute is a String that holds the name of the employees job title
- yearsWorked: The yearsWorked attribute holds the number of years the employee has worked at the company
The class should have the following overloaded constructors:
- A constructor that accepts the following values as arguments and assigns them to the appropriate attributes (fields): employees name, employees ID number, employees department, employees position, and the number of years the employee has worked at the company.
- Do not allow the yearsWorked attribute to be set to values less than zero. If an attempt is made to set the yearsWorked attribute to less than zero, have your constructor set yearsWorked to zero.
- A constructor that accepts the fallowing values as arguments and assigns them to the appropriate attributes (fields): employees name and employees ID number. The department and position attributes should be initialized to the empty string () and the yearsWorked attribute should be initialized to zero.
- A default constructor (accepts no arguments) that initializes the name, idNumber, department, and position attributes to the empty string (). The yearsWorked attribute should be initialized to zero.
Write Get and Set methods for each attribute: name, idNumber, department, position, and yearsWorked.
- Do not allow the yearsWorked attribute to be set to values less than zero. If an attempt is made to set the yearsWorked attribute to less than zero, have your set method set yearsWorked to zero.
Next create a program named EmployeeTest.java to utilize the Employee class you created in the following manner. NOTE: This should be a short program...NO input, just literals and constructors...so the program should not be more than about 30 lines maximum (it could be much less).:
- Instantiate three Employee objects as follows:
Name | ID Number | Department | Position | Years Worked |
Jenny Jacobs | JJ8990 | Accounting | President | 15 |
Myron Smith | MS7571 | IT | Programmer | 5 |
Chris Raines | CR6873 | Manufacturing | Engineer | 30 |
Use the constructor that takes everything for one of the employees, use the constructor that takes only name and id for another employee, and use the constructor that takes nothing for the last employee. Use set and get methods where needed.
- Display the data for each of the three employees to the screen (you do not need to display the lines in the table)
Dont forget to save your EmployeeTest.java file in the same directory as your Employee.java file that contains the Employee class.
Program #2: Car class and program utilizing the Car class
Use UML instead of pseudocode for this program also. Write a class named Car that has the following attributes (fields):
- yearModel The yearModel attribute holds the cars year model (example: 1999)
- make The make attribute holds the make of the car (example: Ford)
- speed The speed attribute holds the cars current speed
The Car class should have the following constructors and other methods:
- The class should have two constructors: (overloaded)
- The first constructor should accept the cars year model and make as arguments. These values should then be assigned to the cars yearModel and make This constructor should assign 0 to the speed attribute
- The second constructor should be a default constructor that accepts no arguments. The constructor should set the yearModel and make attributes to the empty String () and the speed attribute to 0
- Get Method: The class should have get methods for all of the attributes: yearModel, make, and speed.
- Set Method: The class should have set methods for all of the attributes: yearModel, make, and speed.
- Do not allow the speed attribute to be set to less than zero. If an attempt is made to set it to less than zero, do not set the speed attribute, leave it as it is.
- Accelerate Method: The accelerate method should add 5 to the speed attribute each time it is called. Note it is a void method with NO parameters.
- Brake Method: The brake method should subtract 5 from the speed attribute each time it is called. Note it is a void method with NO parameters.
You should save your car class file as Car.java.
Next create a program named CarTest.java to utilize the Car class you created. The program should create a car object with a yearModel of 2007 and a make of Jeep. Then create a car object with yearModel of 2012 and make of Honda. Use one constructor with one car and the other constructor with the other.
Then print the information for each car.
The program should then call one of the car objects accelerate method 5 times. After each call to the accelerate function the program should get and display the car objects current speed. The program should then call the car objects brake function 5 times. After each call to the brake function, the program should get and display the cars current speed
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