{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter-5

Chapter-5 - Exercise 1 public class Foo public static void...

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

View Full Document Right Arrow Icon
COE318 Fall 2007, Olivia Das, Elec. and Comp. Engg., Ryerson University 1 Exercise 1 public class Foo { public static void main( String[] args ) { int[] anIntArray = {1, 2, 3}; test( anIntArray ); for( int value : anIntArray ) System.out.println( value ); } public static void test( int[] anArray ) { anArray = new int[2]; anArray[0] = 4; anArray[1] = 5; } } Output ??
Background image of page 1

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

View Full Document Right Arrow Icon
COE318 Fall 2007, Olivia Das, Elec. and Comp. Engg., Ryerson University 2 Exercise 2 public class Person { private String name; public Person( String n ) { name = n; } public String getName() { return name; } public void setName( String n ) { name = n;} public String toString() { return “Name: “ + name; } } mutable ?
Background image of page 2
COE318 Fall 2007, Olivia Das, Elec. and Comp. Engg., Ryerson University 3 Exercise 2 (continued) public class PersonTest { public static void main(String[] args) { Person p1 = new Person( “Lewis” ); p1.setName( “Loftus” ); System.out.println( p1.toString() ); System.out.println( p1 ); } } Output ?
Background image of page 3

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

View Full Document Right Arrow Icon
COE318 Fall 2007, Olivia Das, Elec. and Comp. Engg., Ryerson University 4 Example: develop a battleship-style Game: “Sink a Dot Com” user against computer goal: sink all the computer’s DotComs in fewest number of guesses Gives a rating based on how well you perform. No GUI. Command-line version. 0 1 2 3 4 5 6 Pets.com
Background image of page 4
COE318 Fall 2007, Olivia Das, Elec. and Comp. Engg., Ryerson University 5 First, a high-level design What the game should do ? User starts the game
Background image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 18

Chapter-5 - Exercise 1 public class Foo public static void...

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

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