Guest User

Untitled

a guest
Dec 10th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. /****************************************************************
  2. *   Developer: Max Jensen
  3. *
  4. *   Purpose of program: Slå en terning, som slår tal mellem 1-6,
  5. *               hvis nr. 1 rammes, sluttes turen.
  6. *
  7. *****************************************************************/
  8.  
  9. import java.util.*;
  10.  
  11. public class Testing5_MaxJensen{
  12.  
  13.     public static void main(String[] args){
  14.  
  15.         System.out.println("Velkommen til terningspillet!\n");
  16.        
  17.         Scanner console = new Scanner(System.in);      
  18.         Random  r       = new Random(); // Benyttelsen af pseudorandom numre
  19.        
  20.         /**************************
  21.         // Let's write some preconditions
  22.         // To make sure we clearify it to be true.
  23.         ***************************/
  24.        
  25.         response(console, "");
  26.        
  27.         public static int response(Scanner console, String prompt){
  28.        
  29.        
  30.         int  sum    =  0;  // make sure we enter the loop
  31.         int  roll1  =  r.nextInt(6) + 1;;
  32.        
  33.                 System.out.print(prompt); // enter a string please
  34.                        
  35.     while(!prompt.equalsIgnoreCase("yes") && prompt.equalsIgnoreCase("no")) { // De Morgan Law ..
  36.             while(!console.hasNext()){
  37.                        
  38.             console.next();
  39.             System.out.println("Not a string! - please try again with letters");
  40.             System.out.print("Yes or no ? ");
  41.             System.out.print(prompt);
  42.                         }
  43.                        
  44.                 } return console.next();
  45.             }
  46.    
  47.        
  48.         } // end of main
  49.     }   // end of class
Add Comment
Please, Sign In to add comment