2016-09-20

posted Sep 20, 2016, 6:07 AM by Samuel Konstantinovich   [ updated Sep 21, 2016, 6:26 AM ]
Quiz Thursday:
All the stuff about java, and writing some code. Not including Objects (today onward)

Do Now: 
Share your coding bat work with me by completing your profile.
Your name should Be:   xx,Last,First   where xx is 06,09, or 10 depending on your period. No spaces!
After you set your profile name, share your work with konstans@stuy.edu.

Then complete Logic-1 ->  in1To10

Did you use an if statement? If you did, try again without an if statement. Just return the boolean.
DO NOT do this:
if( boolean ){
 return true;
}
else{
 return false;
}
INSTEAD you SHOULD do this:
return boolean;




Goal: You down with OOP? (yeah you know me)

1   Objects are things that store information and can perform actions. (Variables and Functions)
Objects you have used in the past:
Netlogo:
    Turtles are objects with many properties.
Python:
    Strings and Lists are objects. They hold data, and have functions attached to them:
      "Hello".upper()  
      L.append(5)

2   Classes - a class is a blueprint for an object, we define the instance variables, and the methods. 

3   re-greeter as a class:
//Greeter.java is a class that acts as a template for creating new Greeters
public class Greeter{
        //an empty class to start
}

//we have a separate file Driver.java (or any other name) 
//This class has a main method and will create Greeter objects
public class Driver{
    public static void main(String[]args){
        //declare object
        Greeter g1,g2,g3;
        //instantiate an object (create new memory)
        g1 = new Greeter();
        //copy the address of the object (points to same memory)
        g2 = g1;
        g3 = new Greeter();

        //Print the address of the object 
        //(this behavior is object specific and can be changed)
        System.out.println(g1);
        System.out.println(g2);//notice that g1 and g2 have the same address
        System.out.println(g3);

    }
}
Comments