Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package week19;
- import java.util.Random;
- import java.util.Scanner;
- public class HigherOrLower {
- public static void main(String[] args) {
- Scanner scan = new Scanner (System.in);
- Random rand = new Random();
- int num1;
- int num2;
- String userInput;
- String userContinue;
- boolean exitProgram = false;
- num1 = rand.nextInt(14 - 1) + 1;
- num2 = rand.nextInt(14 - 1) + 1;
- System.out.println("Card is " + num1);
- while (exitProgram == false){
- System.out.print("(H)igher or (L)ower :");
- userInput = scan.next();
- userInput = userInput.toUpperCase();
- while(exitProgram == false){
- if (userInput.equals("H") || userInput.equals("L")){
- exitProgram = true;
- }
- else{
- System.out.print("(H)igher or (L)ower :");
- userInput = scan.next();
- userInput = userInput.toUpperCase();
- }
- }
- exitProgram = false;
- if (num1 < num2 && userInput.equals("H")){
- System.out.println("Card is " + num2);
- num1 = num2;
- num2 = rand.nextInt(14-1) + 1;
- }
- else if (num1 > num2 && userInput.equals("L")){
- System.out.println("Card is " + num2);
- num1 = num2;
- num2 = rand.nextInt(14-1) + 1;
- }
- else if (num1 == num2 && (userInput.equals("L") || userInput.equals("H"))){
- System.out.println("Card is " + num2);
- num1 = num2;
- num2 = rand.nextInt(14-1) + 1;
- }
- else if(num1 < num2 && userInput.equals("L")){
- boolean exitLoop = false;
- System.out.println("Card is " + num2);
- System.out.print("Card is higher if you lose - play again? Yes/No");
- userContinue = scan.next();
- userContinue = userContinue.toUpperCase();
- while(exitLoop == false){
- if (userContinue.equals("H")){
- exitLoop = true;
- exitProgram = true;
- }
- else if (userContinue.equals("Yes")){
- exitLoop = true;
- num1 = rand.nextInt(14 - 1) + 1;
- num2 = rand.nextInt(14 - 1) + 1;
- System.out.println("Card is..." + num1);
- }else{
- System.out.println("Card is lower you lose - play again? Y/N");
- userContinue = scan.next();
- userContinue = userContinue.toUpperCase();
- }
- }
- }
- else{
- boolean exitLoop = false;
- System.out.println("Card is" + num2);
- System.out.println("Card is lower you lose - play again? Y/N?");
- userContinue = scan.next();
- userContinue = userContinue.toUpperCase();
- while(exitLoop == false){
- if (userContinue.equals("N")){
- exitLoop = true;
- exitProgram = true;
- }
- else if (userContinue.equals("Y")){
- exitLoop = true;
- num1 = rand.nextInt(14 - 1) + 1;
- num2 = rand.nextInt(14 - 1) + 1;
- System.out.println("Card is " + num1);
- }else{
- System.out.print("Card is lower you lose - play again Y/N?");
- userContinue = scan.next();
- userContinue = userContinue.toUpperCase();
- }
- }
- }
- }
- System.out.println("Thank you for playing.");
- scan.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement