Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete class diagram (phase 5 and 6). 17 Questions. 17 To be submitted: 18 Marking Criteria. 20 Appendix A: Sample Output for a completed phase
Complete class diagram (phase 5 and 6). 17 Questions. 17 To be submitted: 18 Marking Criteria. 20 Appendix A: Sample Output for a completed phase 6. 22 Objectives In this assignment you will develop an application which uses inheritance, polymorphism, interfaces and exception handling. This assignment must be implemented:
Note that the mark shown for each phase includes the marks from previous phases as well as the marks for that phase. The assessment item is worth 20% so this mark will be converted to a mark out of 20. Appendix A: Sample Output for a completed phase 6 Note this is a sample only. It did not use a seed of 1 for the random number generator. Your should expect your output with a seed of 1 to be different. On the standard output: run: Simulation Trace: ================= t = 0: group 0 arrived t = 0: Group 0 (3 people) entered t = 2: group 1 arrived t = 2: Group 1 (1 people) entered t = 4: group 2 arrived t = 4: Group 2 (1 people) entered t = 6: group 3 arrived t = 6: Group 3 (1 people) entered t = 7: Purchases collected by Group 0 t = 8: group 4 arrived t = 8: Group 4 (2 people) entered t = 10: group 5 arrived t = 10: Group 5 (1 people) leaves as there is insufficient room for the group t = 11: Purchases collected by Group 1 t = 11: Purchases collected by Group 2 t = 11: Group 0 customer has paid t = 12: group 6 arrived t = 12: Group 6 (2 people) leaves as there is insufficient room for the group t = 12: Group 0 leaves t = 13: Purchases collected by Group 3 t = 14: group 7 arrived t = 14: Group 7 (3 people) entered t = 15: Group 1 customer has paid t = 15: Group 2 customer has paid t = 16: group 8 arrived t = 16: Group 8 (1 people) leaves as there is insufficient room for the group t = 16: Group 1 leaves t = 16: Group 2 leaves t = 17: Purchases collected by Group 4 t = 17: Group 3 customer has paid t = 17: Purchases collected by Group 7 t = 18: group 9 arrived t = 18: Group 9 (2 people) entered t = 18: Group 3 leaves t = 20: group 10 arrived t = 20: Group 10 (1 people) entered BUILD SUCCESSFUL (total time: 0 seconds) In the statistics.txt file: Statistics ========== The number of people served = 6 The lost business = 4 people The following groups are in the shop: ===================================== Group 4 (2 people) arrived at t = 8 Group 7 (3 people) arrived at t = 14 Group 9 (2 people) arrived at t = 18 Group 10 (1 people) arrived at t = 20 The following groups are in the history/log: ============================================ Group 0 (3 people) arrived at t = 0 Group 1 (1 people) arrived at t = 2 Group 2 (1 people) arrived at t = 4 Group 3 (1 people) arrived at t = 6 Group 4 (2 people) arrived at t = 8 Group 5 (1 people) arrived at t = 10 Group 6 (2 people) arrived at t = 12 Group 7 (3 people) arrived at t = 14 Group 8 (1 people) arrived at t = 16 Group 9 (2 people) arrived at t = 18 Group 10 (1 people) arrived at t = 20
- incrementally according to the phases specified in this documentation. If you do not submit a complete working and tested phase you may not be awarded marks.
- according to the design given in these specifications. Make sure your assignment corresponds to the class diagram and description of the methods and classes given in this document. You must use the interface and inheritance relationships specified in this document. You must implement all the public methods shown. Do not change the signature for the methods shown in the class diagram. Do not introduce additional public methods unless you have discussed this with the unit coordinator - they should not be required. You may introduce your own private methods if you need them. Make sure your trace statements display the data according to the format shown in the example trace statements. This will be important for markers checking your work.
- Using the versions of the software and development tools specified in the unit profile and on the unit website.
- ArrivalEvent to represent a group of customers arriving at the shop sometimes there is more than one person doing the shopping. Assuming there is room for the customers to enter the shop, this event will also be responsible for scheduling the CollectItems event which will collect the items to be purchased and for scheduling the next ArrivalEvent.
- CollectItemsEvent - when this event occurs the customer group collects the items for purchase. This event will be responsible for scheduling the PayEvent for the customer group.
- PayEvent represents the customer paying for the items and schedules the LeaveEvent
- LeaveEvent the group has finished their shopping and now leaves the shop with their pruchases.
Description
In phase 1, you are to simulate customer groups of two people arriving every two time units for 20 time units. The only event types that will be processed in this initial phase are ArrivalEvents. There will be no limit to the number of customers in the shop in this phase. However, this phase will require you to set up most of the framework needed to develop the rest of the simulation. At the end of the phase 1 simulation you are to display all the customer groups currently in the shop and all the customer groups that have ever arrived at the shop (this will be a history/log of customers that could be used for future analysis). Given that leave events will not be implemented in this phase, the customer groups in the shop will correspond to the customer groups in the log/history. The output for phase 1 should be similar to the following: Simulation Trace: ============== t = 0: group 0 arrived t = 2: group 1 arrived t = 4: group 2 arrived t = 6: group 3 arrived t = 8: group 4 arrived t = 10: group 5 arrived t = 12: group 6 arrived t = 14: group 7 arrived t = 16: group 8 arrived t = 18: group 9 arrived t = 20: group 10 arrived the following groups are in the shop: ============================== Group 0 (2 people) arrived at t = 0 Group 1 (2 people) arrived at t = 2 Group 2 (2 people) arrived at t = 4 Group 3 (2 people) arrived at t = 6 Group 4 (2 people) arrived at t = 8 Group 5 (2 people) arrived at t = 10 Group 6 (2 people) arrived at t = 12 Group 7 (2 people) arrived at t = 14 Group 8 (2 people) arrived at t = 16 Group 9 (2 people) arrived at t = 18 Group 10 (2 people) arrived at t = 20 the following groups are in the history/log: =================================== Group 0 (2 people) arrived at t = 0 Group 1 (2 people) arrived at t = 2 Group 2 (2 people) arrived at t = 4 Group 3 (2 people) arrived at t = 6 Group 4 (2 people) arrived at t = 8 Group 5 (2 people) arrived at t = 10 Group 6 (2 people) arrived at t = 12 Group 7 (2 people) arrived at t = 14 Group 8 (2 people) arrived at t = 16 Group 9 (2 people) arrived at t = 18 Group 10 (2 people) arrived at t = 20 However, the above output must be generated by running the simulation (i.e. by putting events on the event queue, then removing and processing events from the event queue). Your phase 1 must build most of the framework required to run the simulation. If the output is generated by a series of for loops you have not coded phase 1 correctly and you will be awarded no marks for phase 1. It is important to build phase 1 correctly as it is the foundation for the rest of the assignment. The design and requirements for phase 1 are discussed further below. You must develop the code according to the following class diagram and descriptions of the classes and methods that follow. (If necessary, you may have to use Words view->zoom to magnify and view the class diagram.)Phase 1 class diagram
Figure 1. Phase 1 Class diagram Note: You may add your own private methods to the classes if required, but do not add public methods. The class diagram specifies the design that you are to adhere to. Additional methods and member variables will be added in subseqent phases. See the final class diagram in Figure 2. The above diagram is a sub-set of the final class diagram that will correspond to your final application. It is the class diagram for phase 1 only. For example, when you reach phase 2 and 3 you will add three additional classes (CollectItemsEvent, PayEvent and LeaveEvent) that extend the Event class. In subsequent phases, some of the classes will also require additional instance variables and methods to implement the functionality required in those later phases. The additional variables and methods required are described in each phase and a complete class diagram that includes all the additional classes, variables and methods required for phases 2-6 is shown at the end of phase 6. However, you should not try to complete the whole assignment at once. Make sure that you develop each phase, test it and save a backup before you move on to add the functionality required for the next phase.The IScheduler interface (and the benefits of using an interface)
Note the IScheduler interface that is shown in the class diagram (implemented by the Simulator class and used by the Event class). This interface is to be implemented by the Simulator class as the simulator will be required to schedule events in the event queue according to their scheduled time. As part of an events process() method it is required to schedule other events. The Simulator class has a number of methods, but the only method that is relevant to the event classes is the schedule() method (specified in the interface). By passing the IScheduler to the process() method we limit the events access to the relevant part/interface of the Simulator class. The only method the Event classes can use is the schedule() method. lt is good programming practice to use interfaces in this way, i.e. to program to an interface and only expose the part of the class that is needed. Using an ISchedule interface also means that if you were to use a different simulator or scheduler that also implements the ISchedule interface, no change should be required to the process() methods in the event classes.Implementing Phase 1
To achieve the phase 1 functionality, you have to implement the following:- The ShopModel class.
- The CustomerGroup class.
- The abstract Event class.
- The IScheduler interface
- The ArrivalEvent class
- Set the group size (number of people in this newly arrived group). It will always be 2 in this phase of the assignment. In practice, this number would be selected from an appropriate statistical distribution.
- Obtain the next unique identifier for the group from the shop model (it should use the shop models getNextId() method).
- Create a newly arrived CustomerGroup with the id obtained in (ii) above.
- Add the new customer group to the history/log ArrayList using the shop models logGroup() method.
- Add the new customer group to the ArrayList of groups in the shop using the shop models addGroup() method. Normally this is only done if the group can enter the shop. However, in phase 1 we will allow everyone to enter the shop. There is no limit to the number of people in the shop in phase 1.
- Print a message with details of the group that has arrived (see the sample output showing the simulation trace above).
- Schedule the next arrival event (as discussed in the background notes above). In the next phase we will also schedule a CollectItemsEvent to get the items to be purchased by the group.
- The Simulator class.
- private ArrayList events; // The ordered ArrayList of
- private int clock; // A clock to track the time in the simulation
- private ShopModel model; //A reference to the shop model
- The constructor.
- The initialize() method.
- The run method()
- The schedule method()
- The main method (in Assignment1V1.java) must:
- Create an instance of the ShopModel.
- Create an instance of the Simulator and pass it a reference to the newly created instance of a ShopModel.
- Create an ArrayList of Events (called the event queue). This event queue is to be maintained in order of when the events are scheduled to occur. In later phases this event queue will contain different types of events (e.g. CollectItemsEvent), but in phase 1 we will only be adding ArrivalEvents to the queue.
- Create and add the first ArrivalEvent to the event queue. It is to be scheduled to arrive at time 0.
- Invoke the simulators initialize() method and pass the ArrayList of events to the simulator.
- Invoke the simulators run() method to run the simulation. Pass the number of time steps to run the simulation as the argument to the run method.
- To check that everyone has arrived and is in the shop, use the shop models showGroups() method to display all the customer groups in the shop (i.e. in the groups ArrayList).
- To check that all the customer groups have also been stored in the history/log of customer groups use the shop models showLog() method to display the contents of the history ArrayList.
- An abstract Event class with an abstract process() method. This is because as we develop the simulation we will require more than just arrival events and the different event types will have to be processed in different ways. Each event type will inherit from the Event class and will also be required to implement their own process method. This is an example of polymorphism.
- An IScheduler interface. This is implemented by the Simulator class as the simulator will be required to schedule events in the event queue according to their scheduled time. The Simulator class has a number of methods, but the only method that is relevant to the event classes is the schedule method (specified in the interface). As part of an events process method it is required to schedule other events. The simulator has methods other than its schedule() method. However, the schedule method is the only method that should be of interest to the Event classes so by passing the IScheduler to the process() method we limit their access to the relevant part/interface of the Simulator class. The only method the Event classes can use is the schedule(). lt is good programming practice to use interfaces in this way, i.e. to program to an interface and only expose the part of the class that is needed.
- Add a collectItems () method to the ShopModel class.
- Add a CollectItemsEvent class
- The CollectItemsEvent extends the abstract Event class and must implement its own process() method.
- The CollectItemsEvents process() method must use the shop models collectItems() method to get a collect the purchases for the group (i.e. print out the message). (In a later phase the process model will also schedule the PayEvent for the group.)
- The CollectItemsEvent must also have an instance variable that is a reference to the customer group associated with the order so that it knows which group is collecting their purchases. This means the signature for the CollectItemsEvents constructor will be:
- Have the ArrivalEvents process() method schedule the new CollectItemsEvent six time units after the group arrives (i.e. this will be when they have collected all the items they wish to purchase)
- What should be output by the program at this point? Manually predict this. Run and test it.
- Implement a pay() method in the shop model, which is to
- Print a message when the group pays the shopkeeper as follows:
- Introduce the PayEvent class. The PayEvent class must:
- Extend the abstract Event class
- Have a reference to the customer group that is about to leave
- Implement its own process() method which is to invoke the shop models pay() method.
- Have the CollectItemsEvent schedule a PayEvent for the group 4 time units after purchases have been collected.
- What should be output by the program at this point? Manually predict the output. Run and test it.
- Implement a leave() method in the shop model, which is to:
- print a message when a group leaves the shop as follows:
- remove the group from the ArrayList and
- decrement the number of groups (numGroups) in the shop.
- Introduce a LeaveEvent class. The LeaveEvent class must:
- Extend the abstract Event class
- Have a reference to the customer group that is about to leave
- Implement its own process() method which is to invoke the shop models leave method.
- Have the PayEvent schedule a LeaveEvent for the group 1 time unit after payment is received by the shopkeeper.
- What should be output by the program at this point? Manually predict the output. Run and test it.
- Add a ShopModel constructor that has one parameter that is to be passed the maximum number of customers allowed in the shop when the ShopModel object is created. (The UML diagram in Fig 2 now includes this constructor.)
- Include an instance variable in the ShopModel class that records the number of customer spaces/slots available. This will initially be set to the maximum number of customers allowed in the shop and is to be reduced when customers enter the shop and incremented when customers leave.
- When customers arrive in the shop, if there is room available for all the people in the group to enter the shop, then they can enter the shop to purchase their shopping (i.e. schedule a CollectItemsEvent) as normal.
- If there are sufficient room for all members of the group to enter the shop, print a message as follows:
- Dont forget to increase the number of customer spaces available when a customer group leaves the shop.
- At the end of the simulation, print the following statistics:
- How many customers were served (requires an instance variable to track this it is to be incremented when the customer pays the shopkeeper for the purchases). This is to track the number of customers, not the number of groups served.
- How many customers were lost business (requires an instance variable to track this)
- Display the groups still in the shop at the end of the simulation
- Display the log/history of customer groups that arrived in the simulation.
- Determine how long after an arrival before the CollectItemsEvent is to be scheduled (values to be between 3 and 8 time units).
- Determine the number of people in a group (to be between 1 and 3 people in a group).
- To demonstrate incremental development, your completed Assignment1V1 phase 1 application (zip file with your NetBeans project) is to be submitted in a separate area on Moodle (the assessment 1 phase 1 submission area)
- Phase 6 (or your last completed phase). You are to submit the zip file(s) for your NetBeans project(s). Assuming you have completed to the end of phase 6, you are to submit the zip files with the NetBeans project for both programs (Assessment1V1 (phase 5) and Assessment1V2 (phase 6)). Both versions must be fully documented.
- Report (Word document)
- Description Section: A description of your program describing the phase you have completed (and what it does).
- Testing Section: Explain how you tested your code. What are all the checks you performed to make sure the output is correct? (See examples in the template, but make sure your list is complete.)
- Sample Output Section: Sample output for your last completed phase of the program. If you have reached the phase where you output the statistics results to a file, then your documentation should include the output to the standard output (trace of the simulation) and a copy of the contents the statistics.txt file.
- Bugs/Limitations Section: If there are known bugs they must be documented here otherwise you will lose marks for poor testing as well as the bug in your code.
- Future Developments Section: What additional statistics could you collect that may be of interest to the shop owner? When there is not a constant time between events, there is the possibility that multiple customers might be ready to pay for their purchases at the same time. What modifications would you need to cope with more than one customer being ready to pay for their purchases at the same time?
- Answers to the three questions in the Questions section above.
- Design and Implementation: The functionality must be complete for the phase you have submitted and must be implemented according to the design given in this specification. You must develop the assignment incrementally according to the phases specified.
- Language use: This includes correct usage of inheritance, polymorphism, an interface, correct use of an ArrayList (including correct insertion into the event queue), variable declarations, constant declarations, class definitions, object creation, loop control, use of selection statements, method definitions and use, display of results etc. Marks will be deducted for unnecessary/very inefficient code. Refer to the Guidelines for Java Programming documentation on the unit website for more details.
- Documentation: This includes some of the marks under the layout and code documentation column where you are awarded marks for appropriate comments in your code. You must add comments:
- before each class (describe the class)
- before each method (describe - what the method does, the parameters and the return values)
- and in the body of methods as required, but dont over comment.
- Testing: Part of the marks are for listing the test/checks you performed to make sure each of your completed phases is working correctly. These are to be listed in the report along with the sample output which should include the simulation trace, the results of printing the groups and history lists and the statistics (if you have reached that phase). The output for the trace and statistics should be checked to make sure all aspects of your simulation and the statistics are correct. Marks awarded for testing will include your list of checks in the report as well as for working code that passes all the tests/checks. Note that the documentation also includes a section for bugs/limitations. Ideally, the phase you submit should not have any bugs. However, if the phase you submit has any bugs(i.e. does not pass all its tests/checks) and you do not document them, you will lose marks for inadequate testing and documentation as well as for the function that does not work. If the phase you submit does not have the functionality for that phase, you will be marked according to the last working phase your code demonstrates. Make sure you have backed up a complete, thoroughly tested phase ready for submission before you add the functionality for the next phase.
- Marks will be deducted for late submission according to the university policy (-5% of the total mark for the assignment for each day late).
Functionality: implemented incrementally and using the design specified | Language Use | Testing (thorough testing and documented tests) | Report | Layout and code documentation (Use Javadoc) | Totals | |
Phase1 (Arrive) | /12 | /10 | /2 | /8 | /10 | /42 |
Phase 2 (Collect Items) | /12(P1) +/6(P2) | /10 | /2(P1) + /1(P2) | /8 | /10 | /49 |
Phase 3 (Pay and Leave) | /12 +/6 +/6 | /10 | /2 +/1 +/1 | /8 | /10 | /56 |
Phase 4 A (seat constraint) | /12 +/6 +/6 +/6 | /10 | /2 +/1 +/1 +/2 | /8 | /10 | /64 |
Phase 4 B (statistics) | /12 +/6 +/6 +/6 +/4 | /10 | /2 +/1 +/1 +/2 + /2 | /8 | /10 | /70 |
Phase 5 (write to file) | /12 +/6 +/6 +/6 +/4 +/4 | /10 | /2 +/1 +/1 +/2+ /2 +/1 | /8 | /10 | /75 |
Phase 6 (random values) | /12 +/6 +/6 +/6 +/4 +/4 +/4 | /10 | /2 +/1 +/1 +/2 +/2 +/1 +/1 | /8 | /10 | /80 |
Totals | 42 | 10 | 10 | 8 | 10 | 80 |
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