Lecture3

Lecture3 - Lecture 3 Compound or Binary Assignment...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture 3 Compound or Binary Assignment Operators variable = variable operator expression; is equivalent to variable operator = expression; Decrement and Increment Operators prefix ++x Increment x first, then use new value of x postfix x++ Use current value of x, then increment x prefix --x Decrement x first, then use new value of x postfix x-- Use current value of x, then decrement x Research of Bohm and Jacopini All programs can be written using only three kinds of structures, none of which include the infamous "goto" statement. 1. Sequence Structure {1} Built into the sequential structure of consecutive statements. 2. Selection Structure {3} if, if else, switch 3. Repetition Structure {3} while, do while for loops Example: A Java Class for working with 2D Points. Point.java public class Point { private int x; private int y; public Point ( int xCoordinate, int yCoordinate ) { x = xCoordinate; y = yCoordinate; } public void setX( int xCoordinate ) { x = xCoordinate; } public void setY( int yCoordinate ) { y = yCoordinate; } public void printX() { System.out.printf( "The x-coordinate is %d\n" , x ); } public void printY() { System.out.printf( "The y-coordinate is %d\n" , y ); } // Additional methods will be inserted here. } // End of class Point In addition, the following methods are entered after the comment above and just before the last curly bracket. Note that the methods setX and setY (above) require arguments while getX and getY (below) do not. We also define two methods printX and printY to print the x and y coordinates of a point. The methods setX, setY, printX and printY all return no values, and thus use the void keyword. This method constructs new points (x,y). A custom method to print out the x coordinate of a point. Example: A Java Class for working with 2D Points. Point.java public class Point { private int x; private int y; public Point ( int xCoordinate, int yCoordinate ) { x = xCoordinate; y = yCoordinate; } public void setX( int xCoordinate ) { x = xCoordinate; } public void setY( int yCoordinate ) { y = yCoordinate; } public void printX() { System.out.printf( "The x-coordinate is %d\n" , x ); } public void printY() { System.out.printf( "The y-coordinate is %d\n" , y ); } // Additional methods will be inserted here. } // End of class Point In addition, the following methods are entered after the comment above and just before the last curly bracket. Note that the methods setX and setY (above) require arguments while getX and getY (below) do not. We also define two methods printX and printY to print the x and y coordinates of a point. The methods setX, setY, printX and printY all return no values, and thus use the void keyword....
View Full Document

Page1 / 14

Lecture3 - Lecture 3 Compound or Binary Assignment...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online