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.
Submission reference: IN3685
Hello David, after finishing the first bit of Assignment 2 restaurant. Should we create Restaurant Selector in a different class in the same project or should we start a different one altogether?
The skeleton code we have provided contains an outline RestaurantSelector class. Complete the code in that class. The links to access the code are given in the assignment brief on the first page.
Keywords: assign2
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
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
Submission reference: IN3683
Hello, David I'm having issues with my error keeps coming up and I don't know why could you help me with it please?
code deleted
You have only sent the code. What are the errors that you are having problems with? I have noticed that this code is not correct:
public int getNumberOfRestaurants() // getter method for the NumberofRestaurants{
I would delete the comment - because it is not useful - and reformat your code like this:
public int getNumberOfRestaurants() {
Keywords: assign2
Submission reference: IN3682
hi there , so i wanted to ask if you can give an sample or past exam on how the limited timed assessment would look like. Since i want to start practicing for the real one that will happen on 2nd December.
We will release a 'mock' in time to practice before the real thing.
Submission reference: IN3681
The restaurant test code that was uploaded on moodle has two errors and won't let me compile to test my restaurant class. How do i fix this? These are the lines of code on the test class that are showing up as errors, in specific ".setFoodType" and ".setAveragePrice" :
@Test public void testSetFoodType() { String updatedFoodType = "Italian " + rand.nextInt(10); aRestaurant.setFoodType(updatedFoodType); assertEquals(updatedFoodType, aRestaurant.getFoodType(), "The correct food type was not set."); } and @Test public void testSetAveragePrice() { int updatedPrice = averagePrice + 1 + rand.nextInt(20); aRestaurant.setAveragePrice(updatedPrice); assertEquals(updatedPrice, aRestaurant.getAveragePrice(), "The correct average price was not set."); }
What are the errors? It is your code that is likely wrong in some way. Check that you have the correct spelling of the required method names for the Restaurant class.
Keywords: assign2
Submission reference: IN3680
Here is my code for the removeType method:
code deletedI 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 deletedof the earlier methods I used it in but it seems inefficient.
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
Submission reference: IN3679
Were the test classes not given to us for the second assignment yet?
That's correct. Not given to you yet.
Submission reference: IN3678
whats javas equivalent of the python keyword "pass". For example in python i can do:
if foo == bar: pass else: do somethingin java i want to do something similar for the homework.
if (number >= input) { here is where i want to pass } else { System.out.println("print something"); }
There isn't an equivalent keyword, but you can just leave the curly brackets empty. However, in both cases, you could simply invert the condition and dispense with the else-part:
if foo != bar: do something
if (number < input) { System.out.println("print something"); }
Submission reference: IN3677
How detailed should the Javadoc be in our assignments? For example do we need to write a description of "The getter for the X field" and "@return X" for every getter we write?
Yes, include a sentence describing the purpose and also the @return and @param tags.
Submission reference: IN3676
Here is the code of my class:
code deletedwhy, when call the getDetails method does it return the first string even when the value in motorised it false?
Because you have used =
which is assignment rather than ==
which is the test for equality.
Submission reference: IN3675
Good afternoon, I'm completing exercise 5.10 in the week 13 exercises and I'm confused about what is required of me. I've written:
Book bookName; library.add(bookName); Student studentName; comp3200.add(studentName); MusicTrack songName; track.add(songName);However, I'm not sure that this is what was meant in the question, as the variable names I had made up myself in order to assign something to the ArrayLists. Thank you
Sorry if the question is not clear. What it wants you to do is write the code that creates each ArrayList object and assigns that object to the field names you defined in the previous exercises. Hopefully, that is clearer.
Keywords: ex-5-10
Submission reference: IN3674
Hi, quick question using IntelliJ for the exercises. Some of the questions say we should look at the inspector, but this only applies to BlueJ. Can we still do this somehow in IntelliJ? Should we quickly add our own method that prints all the info to the console? Should we learn how to use the debugger? Or should we just use BlueJ? How do you suggest we approach this? Thanks
You can't do it in IntelliJ. If you want to stick with IntelliJ (which is fine) I suggest that you add a method to print the current state so that you can answer the questions that relate to checking the object state.
Submission reference: IN3673
Write a method called spend that takes one int parameter. The parameter value must be subtracted from the amount field only if the parameter's value is not larger than the value of amount. You may assume that the parameter will never be negative. If the new amount in the money box is now smaller than leastMoney then this method must also update leastMoney.I dont understand how to do this piece of coding. Is there anyway I could get help?
If you come to the drop-in at 3pm in Marlowe PC2 this afternoon then we can give you directed help with that.
Keywords: assign1
Submission reference: IN3672
Good day. I am having issues with the JAR file we are meant to make to submit the assignment 1. Whenever I create it and save it unto my laptop and I try to open it, it never opens. I save it as a JAR file but when I click on it, it doesn't open, please is there any reason for this sir?
You cannot open a JAR file on the desktop, but if you use BlueJ's Project/Open ZIP/JAR menu you can check that the files are in it.
Keywords: jar-file
Submission reference: IN3671
For the second method addMoney am I supposed to write an if method as well? because I have written the code as a ++ and I didn't come up as an error so I'm not sure if I need to write an if
The assignment says, 'The parameter value must be added to the amount field, but only if the parameter's value is greater than zero.' So, there will need to be an if-statement. Be careful about the way you increase the amount
field because using ++ only adds 1 to a variable and you want the method to add whatever value is in the parameter into amount
. The parameter's value will not necessarily be 1. Use the object inspector to check that the field is correct after the call.
Keywords: assign1 , method-addMoney
Submission reference: IN3670
I am unsure what is wrong with my code. This is the only error I have left to fix but I cannot see what is wrong. It says that the error is to do with my spend but I included my whole code
code deleted
Thank you for including your code and the error message, which helps a lot.
If you have 50 pounds in the money box, should it be possible to spend 50 pounds? If so, does your code allow that?
Keywords: assign1 , method-spend
Submission reference: IN3669
For the assignment, when it says write a method addMoney that takes one int parameter, what is supposed to be in the parameter is it the name of the field or you can name it anything?
You can call the parameter whatever you like, but I recommend not calling it 'amount' to avoid a name clash with the amount field. Give it a name that relates to the fact that it is an amount of money being put in the money box.
Keywords: assign1 , method-addMoney
Submission reference: IN3668
Can you reply to emails or this page on the weekend? Can we ask for help on the assignment or we have to do it all ourselves? Do we have to write descriptive javadoc comments in bluej as well?
Yes to all three questions :)
Submission reference: IN3667
Just wanted to check whether my constructor is correct.
code deletedAlso, it is telling me to write a method called spend that takes one int parameter. I do not know how to subtract it from the amount field.
You have the parameters correct, but the body of the constructor is not using the parameter values to initialise the fields. The name parameter must be used to initialise the name field and the amount parameter must be used to initialise the money fields.
Also, you have made lecturers a local variable rather than a field.
Keywords: assign1
Submission reference: IN3666
What am I doing wrong in this line of code? It keeps saying I'm missing a return statement with the last squiggled bracket underlining red but I cant quite tell what I have done wrong:
public boolean method(parameter) { if (condition 1) { return true; } else { if (condition 2) { return false; } } }
This is exactly like one of the examples we gave in Tuesday's lecture on understanding error messages. The compiler needs to know what value to return if both condition 1 and condition 2 are false. There is no else-part in the second if-statement, so the compiler is flagging that up as an error. In your two conditions you have actually covered all the possible values of the parameter, but the compiler cannot work that out.
In fact, if you think about the way you have written your logic, you don't need both of the if-tests. So, the solution in your case is to rewrite the method to use just one if-else statement.
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |