Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************************
- * Developer: Max Jensen
- *
- * Purpose of program: Slå en terning, som slår tal mellem 1-6,
- * hvis nr. 1 rammes, sluttes turen.
- *
- *****************************************************************/
- import java.util.*;
- public class Testing5_MaxJensen{
- public static void main(String[] args){
- System.out.println("Velkommen til terningspillet!\n");
- Scanner console = new Scanner(System.in);
- /**************************
- // Let's write some preconditions
- // To make sure we clearify it to be true.
- ***************************/
- getResult(console);
- } // end of main!
- public static void getResult(Scanner console){
- Random r = new Random(); // Benyttelsen af pseudorandom numre
- int sum = 0; // make sure we enter the loop
- int total = 99;
- int roll1 = r.nextInt(6) + 1;
- while( roll1 != 1 && roll1 < 7 ){
- // Slå med vores terning
- roll1 += sum;
- System.out.println("\nDu slog en: "+ roll1 + "'er");
- if (roll1 > 1){
- roll1 = roll1 + total;
- sum++; // Enter the loop again
- }
- else if ( sum > total){
- roll1 += sum;
- System.out.print("Din totale sum af antal slået tal: "+ sum);
- }
- else if( roll1 <= 1) {
- System.out.println("\nDet var desværre en 1'er!.. Din tur er desværre slut");
- }
- }
- /*******************
- // Make sure the end-user,
- // enters Yes or No.
- ********************/
- String prompt = "";
- System.out.print(prompt); // enter a string please
- while(!prompt.equalsIgnoreCase("yes") && prompt.equalsIgnoreCase("no")) { // De Morgan Law ..
- while(!console.hasNext()){
- console.next();
- System.out.println("Not a string! - please try again with letters");
- System.out.print("Yes or no ? ");
- System.out.print(prompt);
- }
- }
- }
- } // end of class
Add Comment
Please, Sign In to add comment