COMP201: Software Engineering I
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
COMP201: Software Engineering I
Assignment 1.2 (2021/22)
OBJECTIVE
This assignment is mainly about “design/implementation”.
You should be implementing a simulation of part of a drinks machine. This simulation will follow the requirements that have been defined in coursework 1 and follow the use cases that you defined. This simulation will not be a full implementation of the original requirement but a will only implement the coin handling part of the machine. All the UI code is provided for you, so there is no GUI programming required. You are strongly encouraged to start this work as soon as possible.
The purpose of this exercise is to understand the challenges of implementing a design from requirements and the state modelling required. This code will be implemented using a simulated version of the hardware, it would then be possible later to implement a real drinks machine be replacing the simulation code with software drivers connected to real hardware.
Description of problem
Produce code to support a drinks machine simulation in Java using the existing drinks machine simulation code as a base. (This has been made available to you as an Eclipse project).
NOTE You only need to fulfil the requirements of this coursework not the whole of the requirement detailed in coursework 1.
The will need to implement the following
Coin handling
Accept coin codes and credit the user with the correct credit. Ifthe user presses reject, return the users remaining credit. On return of credit the machine should return the change using the highest coin denominations first coins if possible, for example £1.50 can be returned as a pound coin plus one fifty pence coin. However, ifthere are no one pound coins in the machine, this may not be possible and lower denominations will be needed. Your code will have to handle this logic. If some ofthe coin levels are low, it might not be possible to pay out all the change and the balance will be left as a non-zero value.
All the code you will implement is done as part of CoinHandlerManager.java.
Notes, very important to gain full marks read the following
For the submission, you should only change the code in CoinHandlerManager.java.
Testing different currencies
The code can be tested for different currencies by using the drop down box on the main interface.
CoinHandlerManager.java
Handling coins in
public void handleCoinsIn(IMachine machine) {
String code=machine.getCoinHandler().getCoinKeyCode();
This method is called in a loop at regular time intervals.
This method returns either a valid coin code or null of no new coin has been entered. You get the actual coin definition from the code, there is a method in Coin.java, called getCoinFromCode, you should use this method to find out information about the coin. Look at Coin.java to undyerstand the Coin definition. Each name has a name, a code and a worth. For example a pound coin has a code of ‘ef’, a value of 100 and its name is 100p.
The coin definition has getters to retrieve this information. You can get an array of all the coin definitions by calling
Coin.getAllcoins()
This will be useful when paying back change.
Updating the balance
Each time a new coin is entered the balance should be updated. machine.getBalance retrieves the current balance
machine.setBalance sets the balance
You need to use these every time you wish to change the balance.
Very important NO NOT STORE THE BALANCE YOURSELF
Returning the change
The other method you must implement is to return the change
public void returnChange(IMachine machine) {
machine.getDisplay().setTextString("Trying to pay change
back");
Apart from the balancing getter and setter, and the public methods from Coin.java you should use ONLY the following methods in your final code for returning change.
machine.getCoinHandler().dispenseCoin(int code)
This pays back one coin of the given code to the customer.
machine.getCoinHandler().coinAvailable(int code)
This returns true if a coin is available to payout of that code, otherwise it returns false.
For testing purposes you can use the following methods.
public void setHopperLevel(String coinCode,int level)
This is so you can see if your code works correctly, if a coin level is low when paying back change. Your code should not lock up.
Marking criteria
This code will be marked using automatic testing. Different currencies will be tested. Low coin level will be tested when paying back change. The structure and format of the code will NOT be marked for this assignment, however you are strongly encourage to format and comment your code correctly.
2021-12-04