Limited time offer

Get 25% off your order

Use the code below at checkout — offer expires soon.

Your promo codeNURSE24
25%
Expires in: 10:00
Claim my 25% discount
LIMITED OFFER Get 25% off — use code BESTW25 | No AI No Plagiarism On-Time Delivery Free Revisions Claim Now
Skip to content
Get Help Now
Uncategorized

DC1FTS: Foundations of Technology Solutions, Core Tasks 1: OrderBot 1 Note In the following, method names are always followed by (). This serves as a way to distinguish method names from parameters/ class names and it does not mean that the method has no parameters. 2 Write a Method Set up an OrderBot class in BlueJ, with no fields and an empty constructor (no input parameters, nothing in the constructor body). Write a printOrder() method that takes a customer’s order in a restaurant and passes it on to the kitchen staff. The method should take four parameters: • the order (assume the customer can only order one thing at a time) – model this as a String that holds the name of the dish • the table number – this is an int • the time when the order was placed – two parameters

succurely

DC1FTS: Foundations of Technology Solutions, Core Tasks 1: OrderBot
1 Note
In the following, method names are always followed by (). This serves as a way to distinguish method names from parameters/ class names and it does not mean that the method has no parameters.
2 Write a Method
Set up an OrderBot class in BlueJ, with no fields and an empty constructor (no input parameters, nothing in the constructor body). Write a printOrder() method that takes a customer’s order in a restaurant and passes it on to the kitchen staff. The method should take four parameters:
• the order (assume the customer can only order one thing at a time) – model this as a String that holds the name of the dish
• the table number – this is an int
• the time when the order was placed – two parameters of type int, one for the hour and one for the minute
The method returns nothing. It simply displays the order, table number and time on a screen in the kitchen where the staff can see it. Do this by calling System.out.println() three times, with the appropriate parameters.
3 Write a Method after Testing it
3.1 Understand the Requirements – No Code for this Step!
Upon receiving the order, the kitchen staff will give an estimate of the time when the dish will be ready. The calculateWaitTime() method will work out the estimated customer wait time. The method takes four parameters:
• the time the order was placed – two parameters of type int representing the hour (orderHour) and the minute (orderMinute)
• the time the dish will be cooked – another two parameters of type int representing the hour (cookHour) and the minute (cookMinute)
The method should return an int representing the wait duration: the difference between the time the order will be complete and the time the order was placed. The wait duration should be expressed in minutes. If the method input parameters have illegal values or the wait duration cannot be calculated, the method should return -1.
3.2 Write a Test
Set up a test class called OrderBotTest. Write the calculateWaitTimeTest() method. It takes no input parameters and returns nothing. The method should check that calculateWaitTime() works as expected in the following scenarios (bot is an object of type OrderBot):
• cookHour has an illegal value (lower than 0 or greater than 23)
assertEquals(-1, bot.calculateWaitTime(10, 15, 26, 12))
1
• orderMinute has an illegal value (lower than 0 or greater than 59)
assertEquals(-1, bot.calculateWaitTime(10, -10, 10, 30))
1
• the time of the order is after the time when the dish will be ready
assertEquals(-1, bot.calculateWaitTime(10, 10, 9, 30))
1
• the time of the order and the time when the dish will be ready are legal values, in the correct temporal relationship (the latter comes after the former) and the wait time is under one hour
assertEquals(40, bot.calculateWaitTime(10, 10, 10, 50))
1
• the time of the order and the time when the dish will be ready are legal values, in the correct temporal relationship (the latter comes after the former) and the wait time is over one hour
assertEquals(80, bot.calculateWaitTime(10, 10, 11, 30))
1
Which of the five tests above are negative and which are positive? Add some more positive and negative tests to ensure that your method will be properly tested.
3.3 Implement the Method
Compile the test you have written and fix one compilation error at a time by writing the necessary code in the calculateWaitTime() method. Make sure the test passes.
4 Practice with ArrayList
4.1 Add a Field
Add a menu field of type ArrayList in the OrderBot class. This will store the names of all the dishes/drinks/deserts the restaurant serves. Initialise the field in the OrderBot constructor.
4.2 The addDish() and getMenu() Methods
Understand the Requirements – No Code for this Step!
When the chef learns how to cook a new dish, he/she will add the dish name to the menu using the addDish() method. The input parameter is the name of the dish, the return type is void.
The getMenu() method returns the menu field.
4.3 Write a Test
Add a new method called addDishTest() to the OrderBotTest class. The method should test the following scenarios:
• a new dish name is correctly added to the menu
bot.addDish(“Ocean␣pie”); bot.addDish(“Chicago␣deep␣dish␣pizza”); bot.addDish(“Chocolate␣fudge␣cake”); assertEquals(“Ocean␣pie”, bot.getMenu().get(0)); assertEquals(“Chicago␣deep␣dish␣pizza”, bot.getMenu().get(1)); assertEquals(“Chocolate␣fudge␣cake”, bot.getMenu().get(2));
1
2
3
4
5
6
• an attempt is made to add an empty dish name to the menu (the addDish() method should not allow that)
bot.addDish(“”);
assertEquals(3, bot.getMenu().size());
1
2
4.4 Implement the Methods
Compile the tests and write the addDish() and getMenu() methods. Make sure the test passes.
4.5 Reuse a Method to Write a New One
Write a method called printOrderByNumber() that is very similar to printOrder(). It has the same input parameters, except for the first one: instead of the String holding the dish name, pass in an int representing the number of the dish in the menu. Do not rewrite the printOrder() code in your new printOrderByNumber() method. Instead, retrieve the correct dish name from the menu, based on its number, and call printOrder() from printOrderByNumber().