Object-Oriented Programming Comments
Comments
-
OK you can click on the pictures for larger ones. Code can be disorganized without objects, objects let code be organized into components that communicate with each other.
-
blueprint -||- blackprint
-
you used || very good :-)
-
This is such a cool concept!
-
I relied on my thorough Real World knowledge to answer this one.
-
I have installed this software just now
-
That was maybe the most challenging problem I have had to do on Learneroo. I wish I could see other people's solutions.
-
I got Error when attempting task step 2: Cannot find symbol - variable student1
-
@niveoserenity, sorry if it wasn't clear, did you create a Student Object called student1 first? (as described above) ?
-
Got it ^
-
Task 1 at the end: do I do it by creating a new class for instance: right click -> new class -> and name it database1 or what ? if yes why I dont have there any otpions for adding like addperson, but basic Open editor, compile, remove, inspect? thanks
-
@calo, you need to create an instance (an Object) of the class
Database
. So right-click on the icon of the Database class to create an instance of it. (See "Creating Objects" above.) -
I cannot create object. But I find answer in BlueJ FAQs:
I cannot create objects or inspect classes
You may right click a class and the only options are "Open Editor", "Compile", "Inspect" (which is greyed out) and "Remove". This problem is easily solved - the class simply needs to be compiled. The best way to do this is to use the "Compile" button which appears at the left hand side of the BlueJ window - this will compile all classes which are presently uncompiled. Alternatively the "Compile" option available in a Class's popup menu can be used to compile that class by itself. Once a class is compiled, the grey diagonal stripes across the class will disappear and the missing options will become available. -
When i open the package the first message i see is: "Initialising virtual machine...Done. "
At this point i still see the diagonal stripes.
I click on "Compile" and see the message: "Compiling...Done"
The first thing i get in a pop-up is:
"Recompile with -Xliint:unchecked for details"
Followed the steps on this post to disable the pop-up: http://forums.devshed.com/java-help/932889-recompile-xlint-deprecation-details-last-post.html
At this point the diagonal stripes have ONLY disappeared for Staff.
If i try to right click any of the other ones: Database, Person or Student and select "Compile" i get "Compiling...Done" but the diagonal stripes do not disappear.
I'm still doing research, found a couple of posts stating that the methods are old or something like that.
- I did try reopening the package same issue.
Also noticed that if i create a Staff object and try to compile any of the others which are diagonal stripped it deletes the object.
I checked and have the latest up-to-date as per the Help> Check Version... Crtl+V
-Tried Restarting the JVM on Tools.
-Used Show debugger and reproduced issue but i do not see any logging or trace o__O , should it?Further comments, suggestions or help are appreciated.
Best Regards,
Thanks. -
Well one lunch after finally found out why it was only compiling Staff.
Step 2 from instructions state to go to examples/people and click on the BlueJ package.
people on has defined class for staff
Under the same path examples there is another folder named people2, this one has classes for staff and students.
Wohoooo!
-
-_- nope didn't work.... scratch last comment.
-
So solution for my last 3 comments was... used Windows 8 rather than Windows 7. = )
-
i dont have these examples
-
Where is the examples folder in linux?
-
where are located these examples in linux
-
@Jake, I added a download link to the examples folder above.
-
When I create student it create a student like student() and not like new Student(String name, int yearOfBirth, String studentID)
-
hi guys, right click on the object like "staff" press "compile" then right click it again and you can follow the tutorial. You will get an option for new Staff() etc.
-
The only thing I am getting when I bring up a new database is "inherited from object" and 2 void methods - help!
-
Please help someone, i cant find the listAll anywere!??
When i compile al previous steps are gone..... And when i dont i cant find listAll either. What to do?
step for step please?
-
I cant figure this out!
It does not word for me, i cant find listAll please help. step by step?
-
Dr. Rayyan Wilson, MDSc, PhD, specializing in Acupuncture and Anatomy in the United States of America.I am committed to promoting wellness through holistic practices, offering comprehensive care
to patients seeking alternative therapies. For better sleep health solutions, use the SweetNight Sleep discount code to access special offers on medically approved mattresses and pillows.
https://www.reecoupons.com/view/sweetnight -
I'm stumped on this one. I got the answer 20825, but it says this is incorrect. Maybe I misinterpreted the question? This is my code (compiled and verified in an IDE):
class Example {public static void main(String args[]) {
int sum = 0;
int square = 0;
for (int i = 1; i<=50; i++)
{
if(i%2 != 0)
{
System.out.println("i is an odd number: " + i);
square = i * i;
System.out.println("The square of i is: " + square);
sum = sum + square;
System.out.println("The sum so far is: " + sum);
}
}
System.out.println(sum);
}
} -
@Victoria, 1 to 50 only contains 26 odd numbers (see the hint).
-
Thanks, I've got it now. I may well take up the offer of membership in future - I'll see how I get on for now.
-
166650
-
This worked just fitne
int sum=0;
for (int i=1;i<100;i=i+2){sum=sum+i*i;}
System.out.println(sum); -
It just keeps saying: Error, ";" expected
-
wow much hard
-
wow much hard such programming
-
Muy dificil!!!
-
how you make car accelerate
-
@jack, see hint for creating the car. See the mini-Blob challenge above for calling a method on an object. Remember the
.
,()
and;
. -
Car car1 = new Car("green");
car1.accelerate();
car1.accelerate();
car1.accelerate(); -
It's good to learn in this way!!
-
This:
Blob instances have a method blop. Invoke the blop() method of blob1 in a correct line of code
confuses me, is the blop a typo???? -
@Jay, no typo. Blobs can blop().
-
Error: cannot find symbol - class staff
-
car gary = new car(); car.color = "green"; is this wrong ?
-
When you call car.color, you are trying to directly call a private variable, which you can't do from outside of the object (hence why it's private). To set it's value you have to pass in the
String "green" as a parameter when creating the object (also, capitalize the class name, Car): Car gary = new Car("green");
-
Also, I didn't even notice this at first, but when you call an object's variable (that is public), you are going to want to reference the object's name you created it with, and not the name of the class. In your case, if .color was public, you would want to call gary.color and not car.color
-
thanks for that it helped:)
-
return ("ID: " +SID);
after submission results in incorrect? -
Honzis, you don't need to include the brackets around the answer.
-
As a college student who major in EE, I love this kind of learning java !
-
your missing input values here i guess
-
@calo, in this challenge, there is no input.
-
Arent we missing here an input for the options ?
-
yup my bad ..that was before I had the answer right
-
the input values are at the top:
Car c = new Car("green");
System.out.println( c.getColor() );
c.accelerate(5);
System.out.println( c.getSpeed());c.accelerate(-2); System.out.println( c.getSpeed()); c.accelerate(-4); System.out.println( c.getSpeed()); c.accelerate(100); System.out.println( c.getSpeed()); c.accelerate(50); System.out.println( c.getSpeed());
-
anybody know the answer. please post
-
please post answers no comprendo
-
Jack, I will add a hint to help out. You only need to ask for help once! Also, please update your email info. Thanks.
-
oh thank you I had something capitalized that shouldn't have been
-
I have no idea what to do here? Please help me!
-
i figured it out, unbelievable i would never of guessed!
public void accelerate(int amount)
{
if (speed+amount<=0 || speed+amount>=140){speed=speed; } else{ speed=speed+amount; } } public int getSpeed(){ return speed; } public String getColor(){ return color;
-
it is very hard to see the 'big picture'
-
Why is this constructor returning false for the sunroof of car2? ... Car(String clr, boolean roof){
color = clr;
roof = sunroof;
//add 2 parameters above and setup their values
} -
Sorry, I found it :)
-
I did the same thing :P
-
you need to put the variable sunroof before the variable roof
color = clr;
sunroof = roof; -
@Jake, the order of the variable assignment does not matter. (Though the constructor needs to take in the String first in the parameters.)
-
how do I tackle this?
-
you need to set
color
andsunroof
in the constructors (where the comments are). -
how can I correct this?
Car(String clr){
color=clr;
//add 1 parameter above and setup value here
}
Car(boolean roof){
sunroof=roof; -
The second constructor should also take in a variable for
color
and assign it. -
thanks!
-
my code
What is not correct? -
You first need to fix all the compile errors. See the hint I added to get started and simply assign the Car's variables.
-
why its show me a compile error?
("Main.java:33: error: reached end of file while parsing
}
") -
That usually means you're missing an
}
. You can write some of the code for these challenges in BlueJ (or another IDE) so you can see compile errors quickly. -
http://www.learneroo.com//modules/18/nodes/133#com974&togetherjs=NpNuPuKxsj
What is not correct please?? -
You're pretty close, but you need to make sure you're taking the value of the parameter and assigning it to the instance variable.
instanceVariable = parameter;
.The instance variable (declared at the beginning of the class) is on the left side, while the parameter (passed in through the parentheses) is on the right side.
See this solution for the full code.
-
I have the correct answer now, but first of all I thought it would be 16. I didn't think the call to the doubleTotal method would actually change the value of the total variable, because the method is void and the new total doesn't get returned as an integer.
-
How it works then with void? It only do something there, change the value, but type for total is taken from the beginning of the class, when int total; is defined <
-
total
is available to the whole instance, sodoubleTotal
will double it for all the code that uses it. In general, variables are available to the entire scope (marked with{}
) that they are declared in.Declare a variable in a loop? available to that loop. Declare it in a method? available to that method. Declare it in a class (outside any method)? Available to the instance of the class.
-
Thanks a lot as always
-
Can't do the last challenge because the picture isn't loading
Image placeholder with title "colored-code"
-
Sorry about that, it's been fixed.
-
Is it ok that rocketCar is defined before Car ?
-
@calo, doesn't matter. On a computer, each class is usually defined in its own file; the Java compiler can figure it all out.
-
I see now ...I made it eventually, although to public RocketCar(), I only type formula for rocket fuel and nothing else:
public RocketCar()
{
//constructorrocketFuel=10; }
And it worked (in accelerate I called the super accelerate and defined the rocketFuel similar as normal fuel and it worked). I wonder if u stated "contractor: It should call Car's constructor, but also set rocketFuel to 10.", if something more should be there or not.
-
I can't figure out why fuel stays at 20
-
It is updated
-
Hello.
I have correct output, but I changed private variables in class car to non-private.
Is it OK ?
my code: http://www.learneroo.com/user_answers/5096985764 -
Why, in the Student & Staff example, student1.super.toString() doesn't work? I get Error: cannot find symbol - class student1. I've created an instance of Student called student1.
-
I have:
if(speed <= maxSpeed && rocketFuel != 0)
{
speed+=2;
rocketFuel--;
}But its saying it doesn't like my maxSpeed...
Main.java:14: error: maxSpeed has private access in Car
if(speed <= maxSpeed && rocketFuel != 0)
^Why?
-
Hi!
I didn't succeed resolve it.. -
@Raz, you first need to address the compile errors. Don't call
super()
from within a regular method, instead callsuper.methodName()
. And don't try accessing a Car's private fuel, RocketCar only deals with rocketFuel. -
I'm didn't understand What am I being asked to do?
-
@Raz, I added a hint that spells it out in order.
-
my code - Didn't work:/
-
You still need to fix your accelerate method, it's not following the correct syntax. See the correct solution for how to fix it.
-
so with this line of code:
System.out.println(i +". "+ rc);when we say + rc it calls the toString() method of class Car?
can you please explain it why? should't it be something like
+rc.toString()) ; -
As mentioned above, Java has a built-in shortcut that calls the
toString
method of an object when you print it. SoSystem.out.println(i +". "+ rc);
is equivalent toSystem.out.println(i +". "+ rc.toString() );
-
why does super.Car() not work?
-
What method is .Car()?
-
public Picture()
{
// initialise instance variablescircle1.moveUp(); circle1.moveHorizontal(50); circle1.changeColor("yellow");
circle1.makeVisible(); circle1.changeSize(1000); }
Doesn't work because it cannot find symbol "circle1". How do I make it work?
-
You need to create
circle1
first (See the animation above). -
Hi. When you compile circle, create a new instance of circle and then compile Picture, it deletes your instance of circle. So circle1 is deleted before it compiled Picture.
How do I stop it from deleting my instance?
-
Only code that it's the actual source code file is saved. As mentioned, double-click on a Class icon to edit its source code.
-
Many issues with compiling? I imported the missing classes but still many other errors in Canvas.java, can't get it to work!
-
The acclerateMissileToSpeed method is missing a pair of curly braces but that is an compile error in two lines of code i guess.
-
@Peter, thanks, its been fixed.
-
I guess it is something to do with second variable but, could I have a little help here?, thanks
-
@calo, can you find a private instance variable that is being accessed directly from outside the class?
-
now when I got it seems so obvious :)
-
The abstraction for this is mind blowing, at least it's starting now somehow to fall into place in my mind :)
-
I don't get this, and I have a question: Public Missile(int rocketFuel) is our constructor which takes in a parameter, and it has two variables speed and fuel.
with this line of code:
public void accelerateMissileToSpeed(Missile missile, int speed)
we created a new variable with the type of Missile so does missile has the same properties of the constructor? but as a variable? can we use this technique to store in arrays? create our own type and store various information in one slot of an array?apart from my question I can't figure out what is wrong with the code :S please help
-
I am not sure how to access the private instance variable. Does it matter if I use this. or super()?
-
You cannot access private instance variables from outside the object, that's why you use accessor methods.
-
I have the following but i dont see a circle, it gives no errors???
public Circle(int diamterc,int Xpositie,int Ypositie, String kleur){
diamterc=diameter;
xPosition=Xpositie;
yPosition=Ypositie;
color=kleur;
makeVisible();}
-
solved it, i guess the mistake was that is should be
diamter=diamterccan someone confirm this?
-
about the last challenge. the variable speed is private, so millile cant reach that i guess. So i think thats the problem..
i cant figure out the solution doh, so what is the solution?
-
-
Hello,
I got the following error while attempting the constructor task (Note: I made a new constructor with the parameters, which I compiled and had no errors for but after I called(?) this constructor with my parameters which were Circle circle1 = new Circle(60, 89, 98, "red");):
java.lang.NullPointerException
at Canvas.setForegroundColor(Canvas.java:124)
at Canvas$ShapeDescription.draw(Canvas.java:216)
at Canvas.redraw(Canvas.java:167)
at Canvas.draw(Canvas.java:104)
at Circle.draw(Circle.java:181)
at Circle.makeVisible(Circle.java:42)
at Circle.(Circle.java:33)Could you please tell me why this happened?
Thanks,
Utsav -
I can't see the exact code you used. According to your message, the problem happened at line 124 of the Canvas code file, when it was trying to
setForegroundColor
. Do you see anything that could have gone wrong there? -
Hello,
I haven't made any changes to the Canvas class, but here's the code for line 124:
if(colorString.equals("red"))
graphic.setColor(Color.red);Here's the code for my Circle constructor:
public Circle(int diameter, int xPosition, int yPosition, String color)
{
makeVisible();
}Thanks,
Utsav -
The default circle constructor sets the value of various instance variables that are used afterwards. Looks like your constructor takes in multiple parameters but then it doesn't assign their
values. This causes an error when the code later checks the value of
colorString
but it's null. You'll need to set the values of the variables in your constructor. (See https://www.learneroo.com/modules/18/nodes/133). Good luck! -
Won't spoil it, but if you are stuck it is really, really simple... as in 1 character somewhere.
-
Circle[] circles = new Circle[3];
circles[0] = eye1;
circles[1] = eye2;
Result in ... ']' expected ... error in circles[0] definition ? -
@Honzis, you should move your code to the constructor.
-
Not Angry Birds, but... Angry Doggys here we go!
-
Really cool stuff. At first, I wasn't crazy about using BlueJ, but everything is starting to piece together very nicely. Thanks!
-
public void moveCirclesRight() { for (int i=0; i < circles.length; i++) { circles[i].moveRight(); } }
java.lang.NullPointerException
at circles[i].moveRight(); -
How do I get a check on this? You've turned me into a slave for completion checks...
boolean lessonComplete;
public void gimmeCheck(){
lessonComplete = true;
}
interactivePicture.gimmeCheck(); -
Currently there's no online question/check for this page since you do the coding on your computer.
-
How do I get the checkbox for this page? I'm finished the unit... but I can't find any quiz on this page to finish. I just can't stand not having my checkbox checked!!!
-
Just added a simple question so you can mark your progress.
-
I can't do this last task- I've tried to create an array Shape []shapes=new Shape[3];
and then can't instantiate Shape() as it's abstract.
I tried shapes[0]= Circle(); but this doesn't affect the whole Class.
I'd really to understand this. A hint or a cheat would be appreciated. -
@Shane, I can't see your code (since it's offline), but did you use the correct code when creating the Circle?
shapes[0] = new Circle();
If all the shapes are correctly in one Shape array, you can create a method that will callchangeColor
of each Shape:public void changeShapeColor(String color) {
for(int i=0; i<shapes.length; i++){
shapes[i].changeColor(color);
}
} -
Dear Admin,
For the Refactoring Square exercise, moveVertical() method should be moved to the shape super class i believe based on the IS-A test.
The problem is that when i try to compile the Shape class i get>> cannot find symbol method draw().
Of course this would be expected because it is not declared in the Super Class, but since it should be declared in Square which is a sub class i cannot call it through super.
Any hints would be greatly appreciated.
Best Regards.
-
Meh -_-! Sorry Admin.... I had not read about the polymorphic methods... so use abstract for the draw method...
-
How do you do the refactoring task as when you move funcitons such as makeVisible it calls the draw function, which there isnt one in the Shapes class? If the draw function is put in the shapes class it will only draw that shape as draw is called within shapes not the shape (circle). Thanks
-
solved read the next part of the node
-
I did must change the status of draw() method in square from "private" to "public", because of compilation was not possible. Is this correct solution ?
-
draw
can be private in Square on it's own. But it can't stay private when you refactor to inherit from Shape.
calo
Jan 14, 4:31 PMI think it would be good if pictures with schemes could be zoomed