FinalReviewSessionSolutions

FinalReviewSessionSolutions - FINAL REVIEW SESSION...

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

View Full Document Right Arrow Icon
FINAL REVIEW SESSION SOLUTIONS Odometer public class Odometer{ public String odometerToString( int [] odometer) { int index = 0; while (odometer[index] == 0) { // Advance cursor until we get to a real number index++; if (index == 5) break ; // Need to handle last 2 ints regardless } String result = "" ; while (index < odometer. length ) { result += odometer[index]; if (index == 2) { result += "," ; // Comma goes after 3rd char } if (index == 5) { result += "." ; // Period goes after 6th char } index++; } return result; } private void add1TenthMile( int [] odometer) { // Process odometer backwards int index = 6; odometer[index]++; while // Need to set this dial back to 0 odometer[index] = 0; odometer[index - 1]++; index --; } // Process last index if (odometer[index] >= 10) { odometer[index] = 0; } /* Don't need to return anything because an array is an object and is * therefore passed by reference. This means that any changes made to * the array in this method will be seen by the calling method. */ } } DroppingCircles
Background image of page 1

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

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

This note was uploaded on 02/18/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Page1 / 2

FinalReviewSessionSolutions - FINAL REVIEW SESSION...

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

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