XML

COMP3200 Anonymous Questions and Answers Keyword Index

This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.

To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

Keyword reference for method-findBestPrice

2024

Question 46 (2024):

Submission reference: IN3691

hi, I have one error left to fix but I'm unsure where to start

code deleted
testFindRestaurantMultipleClosestHighLow()

Answer 46:

You haven't fully implemented this requirement:

If more than one restaurant is of the target type and nearest to the given price, then the cheapest must be returned.

Keywords: assign2 , method-findBestPrice


Question 45 (2024):

Submission reference: IN3690

Hello, I have two errors and I sort of understand why they are appearing but I don't know how to fix them. Code:

code deleted
Errors: testFindRestaurantLowest() testFindRestaurantMultipleClosestHighLow() I know that I need to change the closest price before I check it with the if statement (as it will always stay at 0) but I'm unsure of how to implement it.

Answer 45:

Having a price difference of zero as your starting point won't work, because you can never find a better price difference among the restaurants. So, a good place to start would be to use an initial value that is higher than any possible price difference.

Also, overwriting bestChoice before you have checked the price difference will always change the selected restaurant regardless of its price.

Keywords: assign2 , method-findBestPrice


Question 39 (2024):

Submission reference: IN3684

Hi Daivd, im currently got one error in the test class, i realise its to do with my code only taking the first element of the array that is the smallest and not going with the one that is the actual smallest. Im not sure where to go next though. Thanks

code deleted

Answer 39:

I think you have to recognise that your choice of a for-each loop means that you intend to examine every restaurant in the list. However, you are subverting that by returning from inside the body of the loop. You should not use a return statement inside a for-each loop. You can only be sure that you have found the right restaurant once the loop has fully completed. So, you need to find a way to remember that you have found a possibility but that you want to keep looking in case of something better later on in the list.

Keywords: assign2 , method-findBestPrice

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
Last modified Fri Jan 17 08:25:20 2025
This document is maintained by David Barnes, to whom any comments and corrections should be addressed.