Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ex8;
- import java.util.Scanner;
- /**
- *
- * @author Monty
- */
- public class Ex8 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int guess, points, random, bet, round;
- double rand;
- points = 1000;
- rand = (13 - 1 + 1) * Math.random() + 1;
- random = (int)rand;
- bet = 0;
- guess = 0;
- round = 1;
- intro();
- while (points > 0) {
- play(bet, random, points, guess);
- round +=1;
- }
- System.out.print("Times gussed: " + round);
- }
- public static void intro() {
- System.out.print("High Low Game\n");
- System.out.print("RULES:\n");
- System.out.print("Numbers 1-6 are low\n");
- System.out.print("Number 8-13 are high\n");
- System.out.print("Number 7 is neither\n\n");
- System.out.print("You have 1000 points.\n ");
- }
- public static int play(int bet, int random, int points, int guess) {
- Scanner input = new Scanner(System.in);
- String answer;
- System.out.print("\nEnter points to risk: ");
- bet = input.nextInt();
- System.out.print("\nPredict (1=high, 0=low): ");
- guess = input.nextInt();
- System.out.print("\nNumber is: " + random);
- if (random <= 6 && guess == 0 || random >= 8 && guess == 1) {
- System.out.print("\nYou win!");
- points = 2*bet + points;
- System.out.print("\n\nYou have " + points + " points.");
- } else {
- System.out.print("\nYou lose.");
- points = points - bet;
- System.out.print("\n\nYou have " + points + " points.");
- }
- if ( points <= 0) {
- System.out.print("\nPlay again? (y/n): ");
- answer = input.nextLine();
- if (answer.equalsIgnoreCase("y")) {
- System.out.print("\n\nYou have " + points + " points.\n");
- } else if (answer.equalsIgnoreCase("n")) {
- points = 0;
- }
- }
- return (points);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment