Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exam 2 Review. variable types boolean - true or false String - "hello" int - 14 double - 3.14159.

Similar presentations


Presentation on theme: "Exam 2 Review. variable types boolean - true or false String - "hello" int - 14 double - 3.14159."— Presentation transcript:

1 Exam 2 Review

2 variable types boolean - true or false String - "hello" int - 14 double - 3.14159

3 instantiation crate a copy of a class for use by another class Utilities screen1 = new Utilities(); must use "new" can then use to call methods: screen1.writeToScreen( "hello", 10, 20 );

4 constructor see page 44 a method that has the same name as the class runs on instantiation of that class see ScreenWorld class

5 screen coordinates what do x and y mean where is (0,0) where is (0, 600) where is (600, 0) where is (600, 600) setLocation( x, y) method

6 GreenfootImage instantiate an object of the GreenfootImage class GreenfootImage myImage = new GreenfootImage( ); this.setImage( myImage ); in an Actor class myImage.drawString(....

7 Lab review the main point of each lab Lab 6 - screen writing Lab 5 - GreenfootImage, VirusPatrol, Virus Lab 4 - moving an Image, Hero( )

8 class / method/ variable definitions method definitions - public void act( ) class definitions - public class Hero extends Actor instance variable definitions - int x = 0; object definition (instantiation) - classname objectname = new classname( );

9 converting String s = "hello"; int i = 0; double x = 3.14159; ints to doubles x = (double) i ; doubles to ints i = (int) x; numbers to Strings s = String.valueOf( i ); s = String.valueOf( x );

10 writing to screen GreenfootImage myImage = new GreenfootImage( ); this.setImage( myImage ); myImage.setColor( Color.RED ); myImage.drawString("hello", 10, 10);

11 code int Looper = 0; while (Looper <= 100) { Looper++; // same as Looper = Looper+1; }

12 code if (x < 20 ) { y = 0; } else // i.e. if x >= 20 ! { y= 1; }

13 libraries greenfoot.*; GreenfootImage java.awt.*;Colors java.lang.Math;Math functions

14 methods with the same name? e.g. writeToScreen( String s, int x, int y ) writeToScreen( int i, int x, int y ) writeToScreen( double f, int x, int y ) writeToScreen( boolean t, int x, int y ) called OVERLOADING parameter list must be different

15 operators = assignment comparisons: = = equals ! = not equals (haven't used this yet) <less than <=less than or equal >greater than >=greater than or equal

16 operators && AND ||OR if ( (x = 10 )) if (( x==0 ) && ( y == 0))

17 if... else if ( x == 10 ) { // do this } else { // do THIS when x is not equal to 10 }

18 not on the test individual MATH functions plotting a curve


Download ppt "Exam 2 Review. variable types boolean - true or false String - "hello" int - 14 double - 3.14159."

Similar presentations


Ads by Google