Object-Oriented Programming Comments

Comments

  • I think it would be good if pictures with schemes could be zoomed

  • 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) ?

  • 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.)

  • 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"

    cont...
  • 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.

    cont...
  • -_- 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)

  • 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?

  • 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 {

    cont...
  • @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

    cont...
  • 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());

    cont...
  • 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){

    cont...
  • 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 and sunroof 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.

  • 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;.

    cont...
  • 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, so doubleTotal 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.

    cont...
  • 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()
    {
    //constructor

    cont...
  • 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 call super.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. So System.out.println(i +". "+ rc); is equivalent to System.out.println(i +". "+ rc.toString() );

  • why does super.Car() not work?

  • What method is .Car()?

  • public Picture()
    {
    // initialise instance variables

        circle1.moveUp();
        circle1.moveHorizontal(50);
        circle1.changeColor("yellow");
    
    cont...
  • 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?

    cont...
  • 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=diamterc

    can 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?

  • got it
    while(missile.getSpeed() < speed){

    i was forgetting the capital S

  • 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");):

    cont...
  • 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);

    cont...
  • 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

    cont...
  • 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.

  • 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 call changeColor of each Shape:

    cont...
  • 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.

    cont...
  • 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.

Contact Us
Sign in or email us at [email protected]