Abdulg

Lobster Pots Java Edition

Oct 6th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1. package lobsterpots;
  2. import java.util.Scanner;
  3. import java.util.Random;
  4.  
  5. public class LobsterPots
  6. {
  7.     public static void main(String[] args)
  8.     {
  9.         int Roll1, Roll2, Input = 0;
  10.         int Pots = 10;
  11.         int Money = 0;
  12.         boolean InputFinished;
  13.         Scanner UserInput = new Scanner(System.in);
  14.         Random RandomNumber = new Random();
  15.        
  16.         System.out.println("Hello and welcome to lobster pots: Java edition!");
  17.        
  18.         for (int Day = 0; Day < 7 && Money >= 30 || Pots != 0; Day++)
  19.         {
  20.             Roll1 = RandomNumber.nextInt(100); // Roll1 = rand() % 100;
  21.             Roll2 = RandomNumber.nextInt(100);
  22.             System.out.println("\nDay: " + Day + "  Money: $" + Money + "  Pots: " + Pots); //printf("Day: %d  Money: $%d  Pots: %d\n", Day, Money, Pots);
  23.             System.out.println("There is a " + Roll1 + "% chance of bad weather today.");
  24.            
  25.             InputFinished = false;
  26.             while (!InputFinished)
  27.             {
  28.                 System.out.print("How many pots would you like to put inshore? ");
  29.                 Input = UserInput.nextInt();
  30.                
  31.                 if (Input <= Pots) InputFinished = true;
  32.                 else System.out.println("You don't have enough pots!");
  33.             }
  34.            
  35.             if (Roll2 < Roll1)
  36.             {
  37.                 System.out.println("It was stormy!");
  38.                 Pots = Input;
  39.                 Money += Input * 10;
  40.             }
  41.            
  42.             else
  43.             {
  44.                 System.out.println("It was fine!");
  45.                 Money += Input * 10 + (Pots - Input) * 20;
  46.             }
  47.            
  48.             InputFinished = false;
  49.             while (!InputFinished)
  50.             {
  51.                 System.out.println("You now have $" + Money + ". Pots are $30 each.");
  52.                 System.out.print("How many would you like to buy? ");
  53.                 System.out.print("(You can afford " + Money / 30 + ") ");
  54.                 Input = UserInput.nextInt();
  55.                
  56.                 if (Input * 30 <= Money) InputFinished = true;
  57.                 else System.out.println("You're too poor!");
  58.             }
  59.            
  60.             Money -= Input * 30;
  61.             Pots += Input;
  62.         }
  63.        
  64.         System.out.println("You finished with $" + Money);
  65.         System.out.println("Thanks for playing!");
  66.        
  67.         UserInput.close();
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment