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

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.

Answer 20:

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


Question 19:

Submission reference: IN3664

Hi, what's the project week will be about in detail?

Answer 19:

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


Question 18:

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 deleted
What is causing this error?

Answer 18:

You have written 'I' (eye) instead of 'l' (el) in println.


Question 17:

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.

Answer 17:

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.


Question 16:

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.

Answer 16:

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.


Question 15:

Submission reference: IN3660

Where can we find the testing file to test the assignment and make sure everything works.

Answer 15:

When I have written it I will put it on the Moodle page.

Keywords: assign1


Question 14:

Submission reference: IN3659

Hi I'm a bit confused because I have 3 errors on this line:

code deleted
sorry 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

Answer 14:

You have a + symbol missing between amount and ". Most".


Question 13:

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!

Answer 13:

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)


Question 12:

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!

Answer 12:

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


Question 11:

Submission reference: IN3656

When do the quizzes start I cant see them on moodle?

Answer 11:

The only quizzes are weekly exercise sheets which we put up last week in this section: Weekly Class Material: Assessment 4


Question 10:

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.

Answer 10:

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


Question 9:

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.

Answer 9:

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


Question 8:

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?

Answer 8:

That means the numbers in your email.

Keywords: week8-exercises


Question 7:

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

Answer 7:

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


Question 6:

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?

Answer 6:

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


Question 5:

Submission reference: IN3650

Hey, i just have bunch of questions to ask if you don't mind to asset me:

  1. I was trying to apply the knowledge that i am getting through the book, using blueJ's figures project, and i was kind of confused about the arrows that was pointing towards the Canvous Class, does it mean by this movement that anything that happens in the created instance from the specific class would be transmitted to the Canvous so it could present it on the terminal?
  2. I want to check it i got the full picture comparing between fields and status, as we know that these could be detected in the inspector menu, so from what i have understood that fields is the created attributes that has been got from the class, and the state is the initial numbers that are visible beside the attribute names "fields", which i anticipate it in that occasion as constructor "because as much as we keep duplicating the creation of instance, we are finding the same numbers".
thanks for your guidance and support, and looking forward for your answers.

Answer 5:

  1. The arrows are called association arrows. An association between two classes can arise for many different reasons but, in essence, it means that one class is aware of, and makes use of, the other class in some way. You can't say any more specifically than that. Later in the course, we will talk about coupling between classes. Which means connectedness between classes. The arrows are some indication that two classes are coupled and that changes to the one at the pointed end of the arrow could have an knock on effect on the class at the other end.
  2. That is essentially correct. The fields are the attributes, and the values stored in the fields of an object are its state. The way that the constructors of the shapes classes have been written means that every Square starts in the same state; every Circle starts in the same state; and so on. But you can change the state of an object after it has been created, and changing the state of one Square (for instance) has no effect on the state of any other Square.


Question 4:

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!

Answer 4:

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.


Question 3:

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

Answer 3:

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


Question 2:

Submission reference: IN3647

What date format should be used for the javadoc `@version` comments? Should it be:

Answer 2:

My preference is for YYYY-MM-DD, but there is no absolute rule for that.

Keywords: javadoc


Question 1:

Submission reference: IN2544

Sample question.

Answer 1:

Sample answer.

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.