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: IN3665
What does this question mean?
Exercise 3.06: Define a setter for the reference field, with the following header: public void setReference(String ref) The body of this method must assign the value of the parameter to the reference field.
Setter methods were explained in the lecture on Monday in week 3. You can find the recording in the Panopto section of the Moodle page, and the slides for that lecture are here: Week 10 Monday - exploring source code
Keywords: setter-method
Submission reference: IN3664
Hi, what's the project week will be about in detail?
It's designed to be a consolidation week, where you have no fresh material in lectures and classes. That should allow you to catch up if you are behind in anything, or even read ahead if you are on top of things.
It is also possible that some additional sessions will be put on your timetable for non-module material, but I don't know any details of that.
Keywords: project-week
Submission reference: IN3663
While attempting to code a print method I got this error: Undeclared method: printIn(java.lang.String) here is the code:
code deletedWhat is causing this error?
You have written 'I' (eye) instead of 'l' (el) in println.
Submission reference: IN3662
hello , i know its a bit early to ask , but is it possible if you can share or upload some sample or past "Time-limited" assessments so i can see how the exam structure will look like.
We will publish a mock before the real thing so that you can practice, but we will just be getting you to solve a programming problem that is similar to ones you have seen before on the course. So it should be relatively straightforward if you are keeping up with the course.
Submission reference: IN3661
I wish to know if the video recording for the live code on Tuesday has been uploaded for those of us who have not done coding before and wanted to have a recap from that to do the assignment.
All the lecture recordings are on the Moodle page. Click on the '<' symbol in the top-right of the page to expose the side bar that has them in.
Submission reference: IN3660
Where can we find the testing file to test the assignment and make sure everything works.
When I have written it I will put it on the Moodle page.
Keywords: assign1
Submission reference: IN3659
Hi I'm a bit confused because I have 3 errors on this line:
code deletedsorry if it looks a bit messy but I can't test it to see if the format is even right because of the errors. I tried a few things to fix it but I'm just confused
You have a + symbol missing between amount
and ". Most"
.
Submission reference: IN3658
Hello. I was wondering about what you explained in Slide 13. I understand the concept of the getter, which retrieves the status or value previously assigned to a specific field. However, while examining the provided code, something caught my attention.
You created an object within the parameters. As I understand it, it's possible to pass an object within the parameters. But if we want to create an object from the same class, do we need to specify the class name followed by a name of our choice for the object? Additionally, how does the compiler pass the information within the method if the object is created this way? Thank you!
This is the code you are referring to, I believe
public void demo(TicketMachine machine) { int cost = machine.getPrice(); System.out.println("Tickets cost " + cost); }
The parameter is of type TicketMachine. That doesn't mean that a new TicketMachine object is being created here. It says that the caller of the method has a TicketMachine object that they have passed into the method. That TicketMachine object could have been created anywhere within the overall program.
If you do need to create an object within code, then you would do it something like this:
TicketMachine aMachine = new TicketMaching(1000);
Then you can access the object via the aMachine variable and pass it to methods such as the demo one like this:
demo(aMachine)
Submission reference: IN3657
I've been trying to understand the concept of the return keyword, and while I've done some research, I'm still a bit confused about when and how to use it. Here's what I think I've understood so far:
The return keyword is used within a method to send a value back to where the method was called. For example, if I have a method add(int a, int b) that adds two numbers, I can return the result of that addition. The value that gets returned is then stored in a variable or used immediately in the calling code.
For instance: int x = y.add(5, 3);
In this case, the numbers 5 and 3 are passed into the add method, which performs the addition, and the result is "returned" and assigned to the variable x.
I understand that using System.out.println() would display the result on the terminal but not store it, as the printed output is erased after the program finishes running. In contrast, the return value remains available in the variable it was stored in, and it doesn't necessarily have to be stored in a new attribute.
However, I am still a little confused about the difference between return and print, and when it's more appropriate to use one over the other. Could you confirm if my understanding is correct and clarify when exactly I should use return instead of just printing the value?
Thank you for your help!
Your understanding is very good. You have described the differences well.
Printing is only useful for human readers interacting with a program. It is much more common for objects to return values from methods rather than print data out. Values that are returned can then be used in the program to do other things. At this stage of the course, we are only looking at relatively small programs, so the significance of returning will not be completely clear. But here is a bit of more advanced code that hopefully shows a little bit of what you can do with return values.
Suppose we want to calculate the average module mark for a student. If a Student object stores a list of their module marks then we can write code that asks the Student object to return the list of marks, and then we can do some calculations with them. The code might look something like this:
int total = 0; int numberOfModules = aStudent.getNumberOfModulesTaken(); // Loop over all the module marks to find the sum (total) of them. for(int moduleMark : aStudent.getModuleMarks()) { total = total + moduleMark; } int average = total / numberOfModules; System.out.println("The average mark is " + average);
The methods getNumberOfModulesTaken and getModuleMarks both return results that are then used in the bit of code that called them. That allows the code to do some calculations and finally print the average for a human reader.
Keywords: return , print , return-vs-print
Submission reference: IN3656
When do the quizzes start I cant see them on moodle?
The only quizzes are weekly exercise sheets which we put up last week in this section: Weekly Class Material: Assessment 4
Submission reference: IN3654
Hello, i was trying to understand the return value while reading the book. from what i have understood from the book, return value is the value saved within the methods and could be called while we invoke methods on the objects if it we are not using the void of course. this is a bit confusing for me could you please explain the return value more explicitly to me and where i can be used.
Also while i was delving more into the context, i have passed by the term of the header, so basically the header jargon is not just applied into the method idea, but instead the header is apparently a synonym of the "data type". thank you for your guidance.
The return type tells you whether a method will pass some data back to the part of the program that called the method. If the return type is void then it won't pass anything back. If the return type is int then the method will likely do some calculations and then pass back the number that is the result of the calculations. Or, if the return type is String, then the method will pass back some text.
To fully understand the concept of return type you need to bear in mind that in a program there are lots of interactions between objects. One object will ask another to do something and that 'do something' might involve a calculation that the first object wants the result of. So, you might see a bit of Java that looks like this:
int resultWanted = someObject.performCalculation(65);
The performCalculation method takes an integer parameter and returns an integer result, so its header would look like this
public int performCalculation(int value)
Once the method has performed the calculation it will have a return statement that sends the result back to be stored in the caller's resultWanted variable. The first object will then use that value for some further calculations, and so on.
Keywords: return-type
Submission reference: IN3655
one question: As the signature indicates, you need to specify the maximum number of students in that class (an integer). so the phrase signature means that we need to provide a data depending of the header type? Because what Ive understood is that signature is the blend between the method name and the parameters.
That is correct. The method signature refers to the method name and its set of parameters. The term 'method header' refers to the additional elements of the visibility (public, private) and the return type (void, int, etc.) but signature is just the name and parameters.
Keywords: method-signature
Submission reference: IN3653
For the week 8 exercises, it asks you to change the value to the digits of your kent login. Does that mean the numbers in your email or your student number?
That means the numbers in your email.
Keywords: week8-exercises
Submission reference: IN3652
When trying to access the needed reading material through kortext, I receive an error that states "Unable to rent book, unexpected error occurred.", for issues such as this, who would I be best to approach to solve it? All emails show that they come from a no reply account so I am a tad confused as to who to ask. Thank you
You need to make sure that you are using the link given on the Moodle page; were you doing that? If not, try it. If the problem persists, I recommend going to the IT services help desk in the library.
Keywords: kortext
Submission reference: IN3651
I was wondering how to access the projects that are named in the book 'Objects First with Java?' In Exercise 1.13 for example, it is asking me to open the house project but I'm not sure how to do that?
You need to download them from the bluej.org site, as detailed on the lecture slides. The link is: https://bluej.org/objects-first/
Keywords: book-projects
Submission reference: IN3650
Hey, i just have bunch of questions to ask if you don't mind to asset me:
Submission reference: IN3649
I was working through 1.1 to 1.7 in the textbook and with a visible circle now in black after trying to change its colour without "", I tried removing the objects from the object bench. I then created a new 'circle1', 'circle2' among other shapes in order to work on Exercise 1.7 in the 1.6 Multiple instances section, but when I made the new circle1 visible, I can still see the original black circle. How would I go about removing this and could you, if possible, explain why the circle remained despite the object being removed? Thank you!
Once you have created a circle and put it on the canvas, you can't actually remove it. You really only have two options: make it invisible again, or move it off the visible canvas area with one of the move methods.
The object bench is not part of the program that is running, so when you remove an object from there, it has no effect on the internals of the program.
Submission reference: IN3648
Could i get a definition and another example of an object? i have started reading 1.1 and i still dont understand what exactly and object is
Don't worry too much at this stage if you are not immediately understanding the concepts. That is perfectly normal. Things will become clearer as you get experience with each topic.
There are lots of ways we could try to explain what classes and objects are. Some will work better than others for different people.
A common way to explain classes and objects is that a class is like a blueprint or a plan for something. It provides instructions for how to build something, but it is not - itself - the thing that is being built. Objects are the (possibly physical) things you use the plan to build. For instance, a set of instructions for a LEGO model would be the class and the LEGO model that is made out of bricks would be the object build from the class/plan. You could choose to individualise the models you build by choosing different colours for the bricks, but still stick to the overall plan for how the bricks are put together. That captures the sense that individual objects, while being broadly the same, can have variations from each other.
Hopefully, that will help.
Keywords: class , object , LEGO
Submission reference: IN3647
What date format should be used for the javadoc `@version` comments? Should it be:
My preference is for YYYY-MM-DD, but there is no absolute rule for that.
Keywords: javadoc
Submission reference: IN2544
Sample question.
Sample answer.
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |