/******************************************* Solutions of Review #3 - Question 1. *******************************************/ k= 0 k= 1 k= 2 k= 3 j= 14 /******************************************* Solutions of Review #3 - Question 2. *******************************************/ int n = Keyboard.readInt(); int row = 1; while ( row <= n ) { int col = 1; while( col <= row ) { if ( row %2 == 1 ) System.out.print("*"); else System.out.print("?"); col++; } System.out.println(); row++; } /* Alternate solution using for loop */ int row, col; System.out.print("Enter integer n: number of lines "); int n = Keyboard.readInt(); for (row =1; row<=n; row++) { for (col=1; col<=row; col++) { if ( row %2 == 1 ) System.out.print("*"); else System.out.print("?"); } System.out.println(); } /******************************************* Solutions of Review #3 - Question 3. *******************************************/ import cs1.Keyboard; public class Q3 { public static void main(String args[]) { int n,a,b,c; System.out.println("Enter 1 to continue, 0 to quit"); n = Keyboard.readInt(); while (n != 0){ a = (int)(Math.random()*10); b = (int)(Math.random()*10); c = (int)(Math.random()*10); System.out.println(a + " " + b + " " + c); if(a == b && b == c) System.out.println("JACKPOT!!!"); n = Keyboard.readInt(); } } } // class Q3 /******************************************* Solutions of Review #3 - Question 4. *******************************************/ public class Calculation { public static void main(String[] args) { // create two Sphere objects Sphere ball = new Sphere(4.0, "ball"); Sphere orange = new Sphere(4.0, "orange"); // compute volume of the ball double ballVol = ball.getVolume(); // print a description of the orange System.out.println(orange); }// end main }// class Calculation public class Sphere { private double radius; // radius of sphere private String type ; // what the sphere is // Constructor: assign values to the two instance variables of the sphere public Sphere(double r, String t) { radius = r; type = t; }// end constructor // instance method getVolume for calculating volume of the Sphere public double getVolume() { return (4./3*Math.PI*Math.pow(radius, 3)); } // define a toString method for showing the type and radius of the Sphere public String toString() { return ("The object is " + type + " with radius " + radius); } }// class Sphere