Write a Java class named Employee to meet the requirements described in the UML Class Diagram below:
Note: Code added in the toString cell are not usually included in a regular UML class diagram. This was added so you can understand what I expect from you.
If your code compiles cleanly, is defined correctly and functions exactly as required, the expected output of your program will solve the following problem:
“An IT company with four departments and a staff strength of 7. Every year, the company allocates a budget of $100,000 to each department. However, this year the company has decided to increase the budget by an additional $800,000 for departments with employees with ranks equal to or greater than 4, and $400,000 to departments with employees with ranks less than 4. You are to write a program that shows a new total budget of each department”
All get and set methods must be ‘final’ methods.
The only direct access to instance variable values is through the set and get methods; no other direct access is ever permitted.
Your output need not be identical to that shown here, but you MUST include all instance values in the output, in the order shown:
Hulk Hogan in rank 8, Dwayne Johnson in rank 6,
Two test harness to use in testing your Employee.java code:
1)
public class TestOrg {
public static void main(String[] args) {
initialValidation( );
realValidation();
} // end main
private static void initialValidation( )
{
System.out.printf( " Beginning of Initial Class Testing %n" );
// Instantiate one object of class using null constructor.
Employee checkEmployee = new Employee();
checkEmployee.setName("Steve Austin");
checkEmployee.setLevel( 8 );
// Use get methods to extract instance values
System.out.printf( "Employee.name: %s %n", checkEmployee.getName( ) );
System.out.printf( "Employee.level: %s %n", checkEmployee.getLevel( ) );
System.out.printf( " End of Initial Class Testing %n%n%n" );
} // end intitalValidation
private static void realValidation(){
System.out.printf( " Updated Class Testing %n" );
//instantiate seven objects of employee class using constructor with arguments
Employee hulk = new Employee("Hulk Hogan", 8);
Employee dwayne = new Employee("Dwayne Johnson", 6);
Employee john = new Employee("John Cena", 3);
Employee shawn = new Employee("Shawn Michaels", 7);
Employee big = new Employee("Big Show", 4);
Employee tripple = new Employee("Tripple H", 7);
Employee brock = new Employee("Brock Lesnar", 4);
//instantiate four objects of unit class using constructor with arguments
Unit sales = new Unit("Sales Department");
Unit IT = new Unit("IT Department");
Unit account = new Unit ("Accounting Department");
Unit operation = new Unit ("Operations Department");
//add employees to unit objects by passing the Employee objects as arguments
sales.addEmployee( hulk );
sales.addEmployee( dwayne );
IT.addEmployee(shawn);
IT.addEmployee(big);
account.addEmployee( john );
account.addEmployee( tripple );
operation.addEmployee(brock);
//this calls the descibe method per each unit object
sales.describe();
System.out.printf("%s%n", "----------------------------------------------------------------------------------");
IT.describe();
System.out.printf("%s%n", "----------------------------------------------------------------------------------");
account.describe();
System.out.printf("%s%n", "----------------------------------------------------------------------------------");
operation.describe();
}
}
2)
import java.util.ArrayList; // Interface provides methods for manipulating objects by index
import java.util.List; // Class implements interfaces List & Collection
public class Unit {
//instance variables
private String unitName;
private double budget;
private List emps = new ArrayList<>();
public Unit(String unitName){
this.unitName = unitName;
this.budget = 100000;
}
public void addEmployee(Employee obj){
emps.add(obj);
if(obj.getLevel() >= 4){
this.budget += 800000;
}else{
this.budget += 400000;
} //end if statement
}
public void describe(){
String temp = "The " + this.unitName + " has been allocated a total sum of " + this.budget
+ "\nbecause it currently has the following Employee(s) : ";
for(Employee x : emps){
temp += x + " "; }
System.out.println(temp);
}
}
Below is the code for your requirement. Please comment if you face any problem or if you want any modification.
Code:
=====
class Employee{
private String name = "";
private int level = 0;
public Employee() {
}
public Employee(String name, int level) {
this.name = name;
this.level = level;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
@Override
public String toString() {
return "Employee name " + name + "in rank " + level;
}
}
Below is the output that I have got after integrating the above code in the main program and Unit program given in the question:
Output:
=====
Beginning of Initial Class Testing
Employee.name: Steve Austin
Employee.level: 8
End of Initial Class Testing
Updated Class Testing
The Sales Department has been allocated a total sum of
1700000.0
because it currently has the following Employee(s) : Employee name
Hulk Hoganin rank 8 Employee name Dwayne Johnsonin rank 6
----------------------------------------------------------------------------------
The IT Department has been allocated a total sum of 1700000.0
because it currently has the following Employee(s) : Employee name
Shawn Michaelsin rank 7 Employee name Big Showin rank 4
----------------------------------------------------------------------------------
The Accounting Department has been allocated a total sum of
1300000.0
because it currently has the following Employee(s) : Employee name
John Cenain rank 3 Employee name Tripple Hin rank 7
----------------------------------------------------------------------------------
The Operations Department has been allocated a total sum of
900000.0
because it currently has the following Employee(s) : Employee name
Brock Lesnarin rank 4
Write a Java class named Employee to meet the requirements described in the UML Class Diagram...
Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...
Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; // Scanner class to support user input public class TestPetHierarchy { /* * All the 'work' of the process takes place in the main method. This is actually poor design/structure, * but we will use this (very simple) form to begin the semester... */ public static void main( String[] args ) { /* * Variables required for processing */ Scanner input = new Scanner( System.in...
Following is the EmployeeTester class, which creates object of the class Employee and calls the methods of that object. The EmployeeTester class is written to test another class: Employee. You are required to implement the class Employee by: declaring its instance variables: name, age, salary. implementing its constructor. implementing its methods: getEmployeeName(), getEmployeeAge(), getEmployeeSalary(), setEmployeeAge(int empAge), setEmployeeSalary(double empSalary) public class EmployeeTester { public static void main(String args[]) { // Construct an object Employee employeeOne = new Employee("Ahmad Abdullah"); //...
Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...
1. Employees and overriding a class method The Java program (check below) utilizes a superclass named EmployeePerson (check below) and two derived classes, EmployeeManager (check below) and EmployeeStaff (check below), each of which extends the EmployeePerson class. The main program creates objects of type EmployeeManager and EmployeeStaff and prints those objects. Run the program, which prints manager data only using the EmployeePerson class' printInfo method. Modify the EmployeeStaff class to override the EmployeePerson class' printInfo method and print all the...
It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming Challenge 2 Employee Class.pdf Program Template: // Chapter 13, Programming Challenge 2: Employee Class #include <iostream> #include <string> using namespace std; // Employee Class Declaration class Employee { private: string name; // Employee's name int idNumber; // ID number string department; // Department name string position; // Employee's position public: // TODO: Constructors // TODO: Accessors // TODO: Mutators }; // Constructor #1 Employee::Employee(string...
Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...
Question 1 1 pts Which of the following is not a valid class name in Java? O MyClass MyClass1 My_Class MyClass# Question 2 1 pts Which of the following statements is False about instance variables and methods? Instance variables are usually defined with private access modifier. Instance variables are defined inside instance methods. Instance methods are invoked on an object of the class that contains the methods. A class can have more than one instance variables and methods. Question 3...
Please fill in the remaining code necessary and follow the instructions below this is an abstract class; it represents an department in the company. This class cannot be instantiated (objects created), but it serves as the parent for other classes. Department – This class represents a department within the company. 1. Provide the implementation (the body) for the following methods: public int getDepartmentID()) public String getDepartmentName()) public Manager getManager()) 2. Fix the implementation for the following method– substitute “blah” with...
public class Pet { //Declaring instance variables private String name; private String species; private String parent; private String birthday; //Zero argumented constructor public Pet() { } //Parameterized constructor public Pet(String name, String species, String parent, String birthday) { this.name = name; this.species = species; this.parent = parent; this.birthday = birthday; } // getters and setters public String getName() { return name; ...