Code.org notes

class, instantiate object, while loop

public class MyNeighborhood { //makes a class that is public, allows it to be accessed by any class
    public static void main(String[] args) { //starts the running of a java program 

      
      Painter PainterPlus = new Painter(); // Instantiates an object (Painter) for class PainterPlus.

      while (myPainterPlus.isOnBucket()) { //while loop that takes paint from a bucket over and over again, as long as the painter is on the bucket
        myPainterPlus.takePaint();
      }
    }
}

extends, super(), make method

public class PainterPlus extends Painter { //"extends" extends a class, so in this case it extends Painter 

    public PainterPlus() {
      super(); // super is reference variable to parent class, used to access variable, method, constructor, in base class from derived class
    }
  
    public void turnRight() { //making method turnRight
      turnLeft();
      turnLeft();
      turnLeft();
    }

    public void moveOrTakePaint() { // if else method
      if (canMove()) {
        move();
      }
      else { 
        while (isOnBucket()) {
          takePaint();
        }
      }  
      
    }
  }

some notes

  • algorithm: instructions to complete task
  • method signature: has name and parameter list
  • ! operator: returns opposite of what is inputted(ie: input of true would output false)
  • concatenation: join 2 strings together
  • edge case: bug at highest/lowest end of a range of values