Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Object Oriented - Advanced Constructors Assistance ? :\
    text
    copied!<p>Can someone please check my code and determine why my pickup function's not working.</p> <p>-- write missing methods for these procedures to occur </p> <ul> <li>Dog bob = new Dog(5);</li> <li>System.out.println(bob);</li> <li>bob.walk();</li> <li>bob.walk();</li> <li>bob.pickUp("Tennis ball");</li> <li>System.out.println(bob);</li> <li>bob.drop();</li> <li>bob.bark(); </li> <li>System.out.println(bob);</li> </ul> <p>-- In my class where I've defined the pickUp method:</p> <pre><code> public Head() { } public void pickUp(String object) { this.object = object; System.out.println("Picked up "+object); } public String getObject() { return object; } public void drop() { System.out.println("Dropped "+object); object = null; } public void bark() { System.out.println("WOOF!"); } public String toString() { return "Head is holding "+ object; } } </code></pre> <p>-- The other class where I'm utilising the method:</p> <pre><code>public class Dog { private int position; private Leg hind1; private Leg hind2; private Leg front1; private Leg front2; private Head head = new Head(); //Constructor for Dog class public Dog(int position) { hind1 = new Leg(position-2); hind2 = new Leg(position-2); front1 = new Leg(position+2); front2 = new Leg(position+2); } public void walk() { front1.step(); front2.step(); hind1.step(); hind2.step(); System.out.println("Pitter patter..."); } public String toString() { return "Head is holding " + head+", Leg at "+hind1.position+", Leg at "+ hind2.position+", Leg at "+front1.position+", Leg at "+front2.position; } public void pickup() { head.pickUp(head.object); } public void drop() { head.drop(); } public void bark() { head.bark(); } </code></pre> <p>PS. head is a new object I've made which belongs to the Head Class, Which is where the first code is from. I'm currently trying to get the second code working to display a picked up object that head picked up.</p> <p>-EDIT : Even if I do put a string in(Eg. head.pickUp("ball");), it still displays "cannot find symbol - method.pickUp(java.lang.String)" when I try running the procedures.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload