the code for Lavb 6 seems to be much less than Lab 5
import java.util.*;
//import java.lang.*; //not necessary to use java.lang.* here?
import FormatIO.*;
public class Lab6 {
public static void main(String[] arg){
//get a random number
//compare the input number with the random number
//make comment if the input number is too high or too law
//stop guessing if the number is right
//print out the number of steps;
int step;
int game = 0;
double aveScore = 0.0;
Random rand = new Random();
Console con = new Console();
boolean playAgain = true;
while(playAgain){
step = 0;
int num = Math.abs(rand.nextInt())%10;
System.err.print(num);
con.println("Please enter a number from 0 - 9 ");
game = game + 1;
for(;

{
int a=con.readInt();
step = step+1;//recording the step while looping
if(a>num)
con.println("Sorry! You guess wrongly. " +
"The number you entered is too high");
else if(a<num)
con.println("Sorry! You guess wrongly. " +
"The number you entered is too low");
else{
break;
}
}
con.println("congrutulations! You entered the right number");
con.println(String.format("you took %d steps to get the right number.",step));
aveScore = (aveScore * (game-1) + step)/game;
con.println("Do you want to play another game?(yes/no)");
String s = con.readWord();
if(s.equalsIgnoreCase("no"))
playAgain=false;
}
con.println(String.format("Your average score of the game is %-4.1f steps",aveScore));
}
}