Considering the A.P. GridWorld Case Study, the Bug class typically has 1 constructor. This constructor can be written as “Bug objectname = new Bug(parameters);”, where the constructor creates a new Bug object using the Bug class. This Bug’s name is written in place of the phrase “objectname”, and its various characteristics are defined in place of the phrase “parameters”. However, if one needs to create multiple Bug objects, then there are multiple constructors for the Bug class, (for example: there are 4 Bug class constructors in Challenge 22).
−Phoenix
Hi Phoenix, consider this statement:
ReplyDelete"Considering the A.P. GridWorld Case Study, the Bug class typically has 1 constructor."
Research and revise when able. Thank you.
“Considering the A.P. GridWorld Case Study, the number of constructors for the ‘Bug’ class depends on the number of ‘Bug’ objects one wants to create, where if someone wanted to create 1 ‘Bug’ object, they would typically just use 1 constructor.”
ReplyDelete−Phoenix
Let's look at it another way. I need a constructor to create a Bug object. No troubles there. Are there different versions of the Bug constructor I can use? If so, how many versions of the Bug constructor are these according to the GridWorld API?
ReplyDeleteTo add a “Bug” object in GridWorld, one can do one of two things. The first of these is to write:
ReplyDeleteLocation “locname” = new Location(“x”, “y”);
Bug “bugname” = new Bug(“parameters”);
world.add(“locname”, “bugname”);
The second of these is to write:
world.add(new Location(“x”, “y”), new Bug(“parameters”));
Both of these will construct a new “Bug” object.
−Phoenix
REVISED SOLUTION:
ReplyDeleteTo add a “Bug” object in GridWorld, one can do one of two things. The first of these is to create a “Bug” with a specified location, color, and/or other parameters by writing:
Location ⟨locname⟩ = new Location(⟨x⟩, ⟨y⟩);
Bug ⟨bugname⟩ = new Bug(⟨parameters⟩);
world.add(⟨locname⟩, ⟨bugname⟩);
The second of these is to create a generic “Bug” with a default location (being random) and color (red) by writing:
world.add(new Bug);
Both of these methods will construct a new “Bug” object.
−Phoenix
How many versions of the Bug constructor are there according to the GridWorld API, and what are the differences between them?
ReplyDeleteThere are two “Bug” constructors. These are the no-args constructor and the constructor. A no-args constructor takes no parameters, while a constructor does.
ReplyDelete−Phoenix
Awesome.
ReplyDelete