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-removeType

2024

Question 56 (2024):

Submission reference: IN3701

for the removeType method, would it be advisable to use a for loop or a while loop?

Answer 56:

I am not sure if you mean a 'for loop' or a 'foreach loop'. You cannot use a for-each loop for that method. You could use a for loop, but we haven't taught for loops yet, so you would need to check your code carefully to make sure it is correct. So, the best choice would be a while loop.

Keywords: assign2 , method-removeType


Question 35 (2024):

Submission reference: IN3680

Here is my code for the removeType method:

code deleted
I understand that you cannot remove an restaurant from the collection whilst it is iterating but I'm not sure how to fix this. In addition, is there a more concise way to write
code deleted
of the earlier methods I used it in but it seems inefficient.

Answer 35:

Remember that variable names should start with a lower-case letter, so avoid calling the variable Restaurant (upper-case 'R') because it causes confusion with the class name Restaurant.

You will need to use a different type of loop for this task. Take a look at how to iterate with a 'while loop' as the preferred solution.

You are comparing the food type correctly, so there is no need to find an alternative to that part. It is not inefficient.

Keywords: assign2 , method-removeType

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.