Guest User

Untitled

a guest
Dec 11th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 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.        
  19.        
  20.         /**************************
  21.         // Let's write some preconditions
  22.         // To make sure we clearify it to be true.
  23.         ***************************/
  24.        
  25.         getResult(console);
  26.        
  27.        
  28.         } // end of main!
  29.            
  30.         public static void getResult(Scanner console){
  31.        
  32.         Random  r       = new Random(); // Benyttelsen af pseudorandom numre
  33.        
  34.         int  sum    =  0;  // make sure we enter the loop
  35.         int total = 99;
  36.         int  roll1  =  r.nextInt(6) + 1;
  37.        
  38.                     while( roll1 != 1 &&  roll1 < 7 ){
  39.            
  40.                 // Slå med vores terning
  41.                 roll1 += sum;
  42.                            
  43.                 System.out.println("\nDu slog en: "+  roll1 + "'er");
  44.                            
  45.         if (roll1 > 1){
  46.             roll1 = roll1 + total;
  47.             sum++;  // Enter the loop again
  48.         }
  49.         else if ( sum > total){
  50.             roll1 += sum;
  51.             System.out.print("Din totale sum af antal slået tal: "+ sum);
  52.         }          
  53.         else if( roll1 <= 1) {
  54.                                
  55.             System.out.println("\nDet var desværre en 1'er!.. Din tur er desværre slut");
  56.             }
  57.                                
  58.                                
  59.         }
  60.                        
  61.                        
  62.                        
  63.     /*******************
  64.     // Make sure the end-user,
  65.     // enters Yes or No.
  66.     ********************/
  67.         String prompt = "";
  68.                        
  69.     System.out.print(prompt); // enter a string please
  70.                        
  71.            
  72.     while(!prompt.equalsIgnoreCase("yes") && prompt.equalsIgnoreCase("no")) { // De Morgan Law ..
  73.         while(!console.hasNext()){
  74.                        
  75.             console.next();
  76.  
  77.             System.out.println("Not a string! - please try again with letters");
  78.             System.out.print("Yes or no ? ");
  79.             System.out.print(prompt);
  80.                            
  81.                         }
  82.                        
  83.                 }
  84.             }
  85.    
  86.         } // end of class
Add Comment
Please, Sign In to add comment