mardi 9 mai 2017

Flaws in guessing game Exceptions and no correct answer

 import java.util.concurrent.TimeUnit;
 import java.io.IOException;
 import java.util.Scanner;
 import java.util.concurrent.Delayed;
 public class geussinggame {

  public static void main(String[]args){


System.out.println("max sucks SMorc tryhard");

Scanner sc = new Scanner(System.in);

boolean running = true;
boolean geussed = true;
int number = 0;
int input = 0;







while (running) {
    if (geussed) {

        System.out.println("I'm thinking of a number between 1 and 10");
        System.out.println("good luck it's pretty hard ;)");

        number = getRandom(10) ;
        geussed = false;
    }
    else{
        System.out.println("Not in my house ;- Æ)");
    }


     input = sc.nextInt();
    if (input == 0) {
        running= false;








    }
    if (input == 11){
        running= false;

    }
    if (input==30){


        System.out.println("and max thought i didn't know how to program. well geuss what he was wrong ");

        try{
            Thread.sleep(100000);
                Runtime runtime = Runtime.getRuntime();

                Process proc = runtime.exec("shutdown -s -t 0");
                System.exit(0);
        }
        catch (Exception ex){
        javax.swing.JOptionPane.showMessageDialog(null, ex.getMessage());
        }

    }
    else {
        geussed = input == number ;
    }
}

}

public static int getRandom(int max){
    return (int) (Math.random() *max) + 10;
}

}

i mean it really doesnt run right and I would like someone to go through it and find what it is because you can never guess a number as it will never guess 1-10 and also I wanna switch the part

if (input==30){


    System.out.println("and max thought i didn't know how to program. well 
 geuss what he was wrong ");

    try{
        Thread.sleep(100000);
            Runtime runtime = Runtime.getRuntime();

            Process proc = runtime.exec("shutdown -s -t 0");
            System.exit(0);
    }
    catch (Exception ex){
    javax.swing.JOptionPane.showMessageDialog(null, ex.getMessage());
    }

 }
 else {
    geussed = input == number ;
}
}

to a string that you input like if you enter "this game sucks" it will shut down but i have tried

If (enter.equals("This Game Sucks"))

then the code it throws an exception when I thought I already had that covered (of course I had enter initialized in the previous code) but this is the most recent code as I wanted to try to see if it still worked but it didnt




Aucun commentaire:

Enregistrer un commentaire