Programming Assignment # 5

$24.99 $18.99

In this homework, you will implement a factory simulator program with object-oriented approach. In the UML diagrams below, access (getter) and modifier (setter) methods are not shown for simplicity. However, you are supposed to implement these methods for each class as well. Implement an Item class with the following UML diagram. Item id : int…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

In this homework, you will implement a factory simulator program with object-oriented approach.

In the UML diagrams below, access (getter) and modifier (setter) methods are not shown for simplicity.

However, you are supposed to implement these methods for each class as well.

  1. Implement an Item class with the following UML diagram.

Item

  • id : int

    • numberOfItems: int

    • Item (id: int)

  • An Item object represents an item generated by the employees working for the factory.

  • Data field id keeps the id of the Item object created.

  • Static data field numberOfItems keeps the number of item objects created.

  • An item is created with an id data field.

  1. You have to use this keyword in the implementation of the constructor. o In the constructor, you also need to increment numberOfItems data field.

    1. Consider the following example which demonstrates the creation of Item object.

Item item = new Item(10);

  1. Implement a Payroll class with the following UML diagram.

Payroll

  • workHour : int

  • itemCount : int

    • Payroll (workHour:int, itemCount:int)

    • calculateSalary() : int

    • toString(): String

  • A Payroll object represents the payroll of the employees.

  • Data field workHour keeps the number of hours an employee has worked.

  • Data field itemCount keeps the number of items an employee has produced.

  • A Payroll object is created with a given workHour and itemCount.

  1. You have to use this keyword in the implementation of the constructor.

  1. Consider the following example which demonstrates the creation of Payroll object.

Payroll payroll = new Payroll(8,15);

    1. Here, the payroll will be created for the 8 hours of working and 15 produced items.

  • calculateSalary() method calculates salary of the employee according to the number of hours an employee has worked and the number of items s/he produced. For each hour an employee works, s/he earns 3 liras and for each item s/he produces s/he additionally earns 2 liras.

    1. As an example, an employee will earn 8*3=24 liras for the working hours and 15*2=30 liras for the items produced with the sample Payroll above; hence a total of 54 liras should be calculated.

  • toString() method returns a String containing information about the work hour and the item count of the payroll. An example string is as following:

    1. The work hour is 8 and the produced item count is 15.

  1. Implement an Employee class with the following UML diagram.

Employee

id : int

name : String

surname : String

workHour : int

speed : int

items : Item[]

payroll : Payroll

+

Employee (id:int, name:String, surname:String, workHour:int,

speed:int)

+

startShift() : Item[]

+

endShift() : Payroll

+

toString() : String

  • An Employee object represents an employee working for the factory.

  • Data field id keeps the id number of the Employee object created.

  • Data fields name and surname keeps the name and the surname of the employee, respectively.

  • Data field workHour keeps the number of hours an employee will work.

  • Data field speed keeps the number of items that the employee can produce in an hour.

  • Data field items array holds the items produced by the employee.

  • Data field payroll keeps the payroll of the employee.

  • An employee is created with an id, name, surname, workhour, and speed values.

o You have to use this keyword in the implementation of the constructor.

o Consider the following example which demonstrates the creation of Employee object.

Employee employee = new Employee(1, “Ahmet”, “Yilmaz”, 8, 3);

    1. Here, an employee has an id of 1, name of “Ahmet”, surname of “Yilmaz”, working hour of 8, and speed of 3. Here, speed represents that the employee can produce 3 items in an hour.

  • startShift() method finds how many items this employee should produce according to speed and workHour values. After that, it creates appropriate number of items with randomly generated ids between 1-100 and put them into items array. It then returns items array.

  • endShift() method creates a Payroll object with employee’s work hour and the number of items s/he creates. It assigns this object to payroll data field. It then returns payroll object.

  • toString() method returns a String with employee’s id and the return value of the payroll object’s toString() method. An example string is as following:

    1. This is the employee with id 1 speed 3. The work hour is 8 and the produced item count is 24.

  1. Implement a Storage class with the following UML diagram.

Storage

  • capacity : int

  • items : Item[]

    • Storage(capacity:int)

    • addItem(item:Item) : void

  • A Storage object represents a storage area for the factory.

  • Data field id capacity keeps the capacity (the maximum number of items that can be stored) of the Storage object created.

  • Data fields items array keeps the items put inside the storage.

  • A storage is created with a given capacity value.

  1. You have to use this keyword in the implementation of the constructor.

    1. Consider the following example which demonstrates the creation of Storage object.

Storage storage = new Storage(100);

  • addItem(item:Item) method adds the item passed as the parameter to the items data field. Note that you need to resize the items array for this.

  1. Implement a Factory class with the following UML diagram.

Factory

name : String

employees : Employee[]

storage : Storage

payrolls : Payroll[]

itemPrice : double

+

Factory( name:String, capacity:int, itemPrice:double)

+

getrevenue() : double

+

getPaidSalaries() : double

+

addEmployee(employee:Employee) : void

+

removeEmployee(id:int) : Employee

addPayroll(payroll:Payroll) : void

  • A Factory object represents a factory with employees.

  • Data field name represents the name of the factory.

  • Data field employees represents employees working for the factory.

  • Data field storage represents the storage area of the factory.

  • Data field payrolls represents the payrolls belonging to the employees.

  • Data field itemPrice represents the price for one item (Suppose that all items have the same price).

  • A factory is created with a given name, capacity, and itemPrice value.

  1. You have to use this keyword in the implementation of the constructor.

  1. In the constructor, you also need to create a Storage object with the given capacity and assign it to storage data field.

    1. Consider the following example which demonstrates the creation of Factory object.

Factory factory = new Factory(“My Factory”, 100, 5);

  • getRevenue() method returns the revenue according to the number of items in the storage data field and itemPrice data field.

  • getPaidSalaries() method calculates the paid salaries of the employees according to the payrolls array. Note that you need to use calculateSalary() method of payroll objects in payrolls array.

  • addEmployee(employee:Employee) method adds an employee to the employees array.

    1. Note that you need to resize the employees array for this.

    1. Then, you need to call startShift() method of the newly added employee and add all the items returned from startShift() method to storage, using addItem(item:Item) method of storage data field.

  • removeEmployee(id:int) method removes the employee from employees array.

  1. If there are no employees, it prints an appropriate error message.

  1. If the employee with a given id is not found, it prints an appropriate error message. o If the employee is found, it removes employee from the employees array.

    • Note that you need to resize the employees array for this.

  1. Then, you need to call endShift() method of the newly removed employee and call addPayroll(payroll:Payroll) method with the returned payroll by

the endShift() method.

    1. At the end, you need to return the removed employee.

  • addPayroll(payroll:Payroll) method adds the payroll passed as the parameter to the payrolls data field. Note that you need to resize the payrolls array for this.

You are given a simple scenario (Test.java) to test your class implementations. Note that the output of the example test class is as the following:

There are no employees!

Employee does not exist!

This is the employee with id 1 speed 3. The work hour is 8 and the produced item count is 24.

This is the employee with id 2 speed 2. The work hour is 6 and the produced item count is 12.

This is the employee with id 3 speed 1. The work hour is 10 and the produced item count is 10.

Revenue: 230.0

Paid salaries: 164.0

Total item produced: 46

There might be other test cases too. Therefore, please pay attention to use the same class, method and variable names in your implementations. You are allowed to increase the number of methods in the classes; however, you cannot decrease the number of them. You are not allowed to use ArrayLists in the homework! You can only use Arrays.

The produced output should be identical to that of this example as your programs will be graded by an auto-grader.

Submission Instructions

Please zip and submit your files using filename YourNumberHW5.zip (ex: 150713852HW5.zip) to Canvas system (under Assignments tab). Your zip file should contain the following 10 files:

  1. 5 Java source files: Item.java, Payroll.java, Employee.java, Storage.java, Factory.java.

  1. 5 Java class files: Item.class, Payroll.class, Employee.class, Storage.class, Factory.class.

Important Notes:

  1. Your program will be tested with an auto-grader. So it should take the input exactly the same in the example and it should print the output exactly the same in the example. Otherwise, your program may fail.

  1. Your program should execute correctly for different test cases.

  1. Write a comment at the beginning of each program to explain the purpose of the program.

  1. Please do not write any package name at the beginning of your code.

  2. Write your name and student ID as a comment.

  3. Include necessary comments to explain your actions.

  4. You are allowed to use the materials that you have learned in lectures & labs.

  5. Do not use things that you did not learn in the course.

  1. Each student should submit his/her own homework. You can discuss with your peers about the homework but you are not allowed to exchange code or pseudocode. This also applies to material found on the web.

  1. In case of any form of copying and cheating on solutions, you will get FF grade from the course! You should submit your own work. In case of any forms of cheating or copying, both giver and receiver are equally culpable and suffer equal penalties.

All types of plagiarism will result in FF grade from the course.

11. No late submission will be accepted.

Programming Assignment # 5
$24.99 $18.99