Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lobsterpots;
- import java.util.Scanner;
- import java.util.Random;
- public class LobsterPots
- {
- public static void main(String[] args)
- {
- int Roll1, Roll2, Input = 0;
- int Pots = 10;
- int Money = 0;
- boolean InputFinished;
- Scanner UserInput = new Scanner(System.in);
- Random RandomNumber = new Random();
- System.out.println("Hello and welcome to lobster pots: Java edition!");
- for (int Day = 0; Day < 7 && Money >= 30 || Pots != 0; Day++)
- {
- Roll1 = RandomNumber.nextInt(100); // Roll1 = rand() % 100;
- Roll2 = RandomNumber.nextInt(100);
- System.out.println("\nDay: " + Day + " Money: $" + Money + " Pots: " + Pots); //printf("Day: %d Money: $%d Pots: %d\n", Day, Money, Pots);
- System.out.println("There is a " + Roll1 + "% chance of bad weather today.");
- InputFinished = false;
- while (!InputFinished)
- {
- System.out.print("How many pots would you like to put inshore? ");
- Input = UserInput.nextInt();
- if (Input <= Pots) InputFinished = true;
- else System.out.println("You don't have enough pots!");
- }
- if (Roll2 < Roll1)
- {
- System.out.println("It was stormy!");
- Pots = Input;
- Money += Input * 10;
- }
- else
- {
- System.out.println("It was fine!");
- Money += Input * 10 + (Pots - Input) * 20;
- }
- InputFinished = false;
- while (!InputFinished)
- {
- System.out.println("You now have $" + Money + ". Pots are $30 each.");
- System.out.print("How many would you like to buy? ");
- System.out.print("(You can afford " + Money / 30 + ") ");
- Input = UserInput.nextInt();
- if (Input * 30 <= Money) InputFinished = true;
- else System.out.println("You're too poor!");
- }
- Money -= Input * 30;
- Pots += Input;
- }
- System.out.println("You finished with $" + Money);
- System.out.println("Thanks for playing!");
- UserInput.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment