XML

COMP3200 Anonymous Questions and Answers

This page lists the various questions and answers. 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.

We have taken the liberty of making some minor typographical corrections to some of the questions as originally put. Although most of the questions here will have been submitted anonymously, this page also serves to answer some questions of general interest to those on the course.


Question 60:

Submission reference: IN3706

Hi David, I'm in the process of finishing up my assignment 2 however for the challenge method there is one failure I keep getting in the test class for the findRestaurantClosest test. this is my code for the findBestRestaurant method:

code deleted
I've tried messing around with the logic but can't seem to fix the error.

Answer 60:

I think it's because you aren't preferring a cheaper restaurant when two are within the same distance.


Question 59:

Submission reference: IN3704

I've been running the test for the RestaurantSelection class and I can't seem to work out where I've gone wrong in this section of my code as it keeps saying the 2 tests failed are 'FindRestaurantLowest' and 'FindMultipleRestaurantClosest', do you know what I've done wrong or missed out?:

code deleted

Answer 59:

I am confused, because when I run your code with the test class it passes all the tests. I also could not see a logical error in it when I ran it.


Question 58:

Submission reference: IN3705

Main' is not allowed to run in parallel. Would you like to stop the running one? My code is not running and this is the error message that is produced.

Answer 58:

Either click on the Red square in IntelliJ to stop the running process or quit IntelliJ and restart it.


Question 57:

Submission reference: IN3702

hi, I keep getting this error in the test cases:

org.opentest4j.AssertionFailedError: Expected Restaurant 2 serves Food type
5X food at around 3000 pounds but the result was Restaurant 2 serves Food
type 5X food at around 3000 pounds ==> expected:
Restaurant@53ca01a2 but was: Restaurant@358c99f5
Expected :Restaurant 2 serves Food type 5X food at around 3000 pounds
Actual	 :Restaurant 2 serves Food type 5X food at around 3000 pounds
i tried to search it up nut it wasn't much help

Answer 57:

You probably have an extra space at the end of the string returned by a Restaurant's toString method.


Question 56:

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 55:

Submission reference: IN3700

how do you upload the work from intellij. How do i convert it to a JAR file?

Answer 55:

Zip the src folder and upload that.


Question 54:

Submission reference: IN3699

hello, for assignment 2, once we input both the tests, if theres no errors in the tests does that mean our code is correct?

Answer 54:

It's not an absolute guarantee, but it's a good indication.

Keywords: assign2


Question 53:

Submission reference: IN3698

hi prof , do we need to do anything on the main class or do i just leave it as it it(empty)

Answer 53:

You don't have to do anything with the Main class. If you are using the JUnit test classes to check your code, then you can leave Main empty. If you aren't using the test classes then you will probably want to write your own testing code in main as we demonstrated in last week's lectures. But we won't be marking you on any code in the Main class.

Keywords: assign2


Question 52:

Submission reference: IN3697

hi, I have tried to find the mistake for hours and I still dont understand what is wrong because the error that comes up says I am comparing 2 strings with an '==' but I am just reassigning the variable so when, it is displayed it has an X next to the number, but it seems to not work. Here is my code:

    public void setType(String name, String type) {
	 code deleted
		String updatedType = restaurant.getFoodType() + "X";
		return ;
         code deleted
	    }
Thank you.

Answer 52:

If you want to change the type of a Restaurant object then you have to call the type setter method on it. At the moment, you are just getting the food type and changing the local variable, so you are not mutating the Restaurant object at all.

Keywords: assign2 , method-setType


Question 51:

Submission reference: IN3696

I have created a folder for an IntelliJ project, but trying to open the same project in BlueJ does not seem to work as it requests me to:

  1. include a BlueJ file within the folder, or
  2. change the parent directory for the folder (when trying to open non BlueJ file)
What can I do to run BlueJ projects initially created in IntelliJ without this issue?

Answer 51:

Use the Project/Open Non BlueJ option and select the src folder.


Question 50:

Submission reference: IN3695

in my assignment 2 project some private fields say: make '<something>' final is this something i should ignore for now or should i look into that.

Answer 50:

You can accept the suggestion if the field is one that won't be changed by any of the methods in the class. For instance, if it doesn't have a setter. A final field is one whose value is fixed for the life of the object.

Keywords: final-field


Question 49:

Submission reference: IN3694

Hi, for the 2nd assignment my intelliJ code keeps autoformatting so its all one one line for methods with less code. is it okay to leave as that. for example:

code deleted

Answer 49:

I think you will find that it is just 'collapsing' the methods to save space. There should be a '>" symbol in the left margin that you can click to expand the code again.


Question 48:

Submission reference: IN3693

Though I'm not very experienced with the language, I'm familiar with VS Code and intended to keep using it as I have in the past. All was going swimmingly until I reached the point of this week's exercises (Week 15) where I had to work with the music-orgasnizer. I'm getting this error on the MusicPlayer class.

The import javazoom cannot be resolvedJava(268435846)
package javazoom.jl.decoder does not exist(errors(1): 5:8-5:16)
package javazoom

Answer 48:

You will need to add the javazoom library to your project. You can find it as jl1.0.1.jar in the chapter04 directory that you downloaded for the exercises.


Question 47:

Submission reference: IN3692

Hello, I'm actually kind of curious of the data that we would be assigned for the 1h:30min quiz that is our last assessment for the current model, is there by any chance could you announced when is it been scheduled? Thanks in advance for your assistance.

Answer 47:

The time-limited assessment will take place in your regular class slot in week 11. It will cover material taught in the course up to that point and we will provide a mock in advance for you to practise on.

Keywords: assign5


Question 46:

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:

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 44:

Submission reference: IN3689

code deleted
This is a copy and paste of my code in the RestaurantSelection class. I'm very confused on how to fix the error at "restaurants.add(restaurants);" I tried the suggestions and I just get more error messages. How do I fix this?

Answer 44:

You are trying to add the list (restaurants) to the list when you should be adding the Restaurant parameter (restaurant) to the list. By the way, you have mis-spelled restaurants.

Keywords: assign2


Question 43:

Submission reference: IN3688

Hi! When submitting the assignment, should we remove the test classes from our project? Also, how do we compile the assignment into a jar file in intellij (if its of any relevancy, i am on a windows machine)? There seems to be a video only for bluej. If we submit as a zip, should we just zip the entire folder that you gave us? Thanks, and sorry for the amount of questions.

Answer 43:

Your questions are all fine. For an IntelliJ or VSCode project there is no need to remove the test classes or create a jar file. Just zip the whole folder containing your project and submit that.


Question 42:

Submission reference: IN3687

Hi, I just started recently using intellij, and for some reason on some files it doesnt let me run the code even though there are no errors that show up. But on some files I am able to run the code. So I am confused what would be the reason of why this is happening. Thank you.

Answer 42:

It will only let you run code that is either a test class - if you have JUnit set up - or a class containing a main method. This is one of the ways that BlueJ differs from other IDEs. In BlueJ, you can interactively work with any class but in JUnit a program needs a class with a main method.


Question 41:

Submission reference: IN3686

public class Main {
    public static void main(String[] args) {
	comp3200;
    }
    public Main{
	comp3200;
    }
}
how would I define the comp3200 as a local variable, and then initialise it with a new Module object? kinda confused since there isn't a type for it like int comp3200; or String comp3200;

Answer 41:

Both int and String are data types, and can be used to declare variables; e.g.:

int amountOfMoney;
String nameOfTheGame;

The important thing to bear in mind is that every class you define can be used in the same way as all the pre-existing types. So, if you declare a class called ClockDisplay, you can use it to define a variable:

ClockDisplay noTimeLikeThePresent;

and initialise the variable with a ClockDisplay object:

noTimeLikeThePresent = new ClockDisplay();

The exercise is asking you to do exactly the same sort of thing, but the class is called Module and the variable is called comp3200.

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.