Ex8CrazyControlClass

Ex8CrazyControlClass - crazy.printSomethingElse(num);

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

View Full Document Right Arrow Icon
Example 8: Control Wrap-Up (so far) /* class CrazyControl * Author: Dr. Franklin * Purpose: Challenge your understanding of the control flow of a program, * integer operators, and output statements. */ import java.util.Scanner; public class CrazyControl { public static void main(String args[]) { Scanner input = new Scanner( System.in ); // read from screen int num; System.out.print("Enter a number: "); num = input.nextInt(); System.out.print("\n"); CrazyClass crazy = new CrazyClass(num); System.out.printf("%d people ",num); if ((num % 2) == 0) System.out.print("embarked "); else System.out.print("set off "); System.out.print("on a journey of "); crazy.printSomething(); System.out.println("proportions."); if (num > 1) System.out.printf("They "); else System.out.printf("He/she ");
Background image of page 1

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

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

Unformatted text preview: crazy.printSomethingElse(num); System.outprintln("in circles."); } // end of method main } // end of class CrazyControl /* class CrazyClass * Author: Dr. Franklin * Purpose: Challenge your understanding of the control flow of a program, * integer operators, and output statements. */ public class CrazyClass { private int number; public CrazyClass(int n) { number = n; } public void printSomething() { if (number > 10) System.out.print("epic "); else if (number > 5) System.out.print("moderate "); else System.out.print("pitifully small "); } public void printSomethingElse(int num) { System.out.println("walked . .."); while (num > 0) { System.out.println("and walked. .."); num = num – 1; } } } // end of CrazyClass...
View Full Document

This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 2

Ex8CrazyControlClass - crazy.printSomethingElse(num);

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