Iteration Homework
Homework Code
public class Guessing {
static int b = randomNumber();
static boolean gameRunning = true;
public static int randomNumber() {
double a = (1 + Math.random() * 100);
return ((int) Math.floor(a));
}
public static void newNumber(){
b = randomNumber();
}
public static String guessing(String guess) {
int c = Integer.valueOf(guess);
if (c != b) {
if (c > b) {
return (c + " was not the number," + "\nlower\n");
}
if (c < b) {
return ( c + " was not the number," + "\nhigher\n");
}
}
if (c == b) {
gameRunning = false;
return "You guessed it! The number was " + b;
}
return "error";
}
}
public class Main{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
while(Guessing.gameRunning){
System.out.println("Type Guess Here: ");
String input = scanner.nextLine();
System.out.println(Guessing.guessing(input));
}
}
}
Main.main(null);