Chapter-5

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

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 DocumentRight 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 DocumentRight 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 DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/28/2008 for the course COE 318 taught by Professor Ken during the Fall '08 term at Ryerson.

Page1 / 18

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

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

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