0% found this document useful (0 votes)
10 views3 pages

Chapter 6 Fishing Game

java

Uploaded by

jikitacwb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Chapter 6 Fishing Game

java

Uploaded by

jikitacwb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Random;

import java.util.Scanner;

public class FishingGame {

//display a message points

public static void displayMessage(int points) {

if (points >= 50) {

System.out.println(" You are a good fisherman");

} else if (points >= 30) {

System.out.println("Nice Job There is a lot fish inside of that bucket


");

} else if (points >= 10) {

System.out.println("Good Catch");

} else {

System.out.println("Keep trying");

public static void main(String[] args) {

// Set up the items and their points

String[] items = {"Huge Fish", "Old Shoe", "Little Fish", "Goldfish",


"Boot", "Trophy Fish"};

int[] points = {10, 1, 2, 5, 0, 15};

// Variables for the game

int totalPoints = 0;
boolean continueFishing = true;

Scanner scanner = new Scanner(System.in);

Random random = new Random();

// Game loop

while (continueFishing) {

System.out.print("Do you want to go fishing? (yes/no): ");

String userInput = scanner.nextLine().toLowerCase();

// Check user input

if (userInput.equals("no")) {

continueFishing = false;

} else if (userInput.equals("yes")) {

// sim 0 to 5

int roll = random.nextInt(6);

System.out.println("You caught a " + items[roll] + " worth " +


points[roll] + " points.");

totalPoints += points[roll];

} else {

System.out.println("Invalid input. Please enter 'yes' or 'no'.");

// loop ends total points and message

System.out.println("\nYour total fishing points: " + totalPoints);

displayMessage(totalPoints);
scanner.close();

You might also like