Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this program but I can't run it on eclipse why these errors I think its shou ld I import two class and how

I have this program but I can't run it on eclipse

why these errors

I think its shouimage text in transcribedld I import two class and how can I solve this?

**********************************************

/******** below is the code *********/

/********* GameScore.java *********/

package code; public class GameScore { public int trials; public boolean result; public GameScore(int trials, boolean result) { this.trials = trials; this.result = result; } public GameScore() { } } 

/********* Main.java *********/

package code; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class Main { public static int isValid(String strNum, int maxNumber) { int num = -1; if (strNum != null) { try { num = Integer.parseInt(strNum); if (num  maxNumber) num = -1; } catch (NumberFormatException nfe) { return num; } } return num; } public static void main(String[] args) { // Random values generator Random random = new Random(); // Scanner to read input Scanner keyboard = new Scanner(System.in); // User Level and name String name; Level level; // MaxRandom and number fo trials int maxRandom = 0; int maxTrials = 0; // Temporary values int choice = 0; boolean invalidInput = false; // Prompting for a name System.out.print(" Enter you name: "); name = keyboard.nextLine(); // Choosing a difficulty Level do { if (invalidInput) { System.out.println("Enter only a number in range [1," + Level.values().length + "] !"); } invalidInput = false; System.out.println(" Select Difficulty Level: "); for (int i = 0; i  Level.values().length) { invalidInput = true; } } catch (NumberFormatException ex) { invalidInput = true; } } while (invalidInput); level = Level.values()[choice - 1]; // Setting maximum random and number of trials switch (level) { case BEGINNER -> { maxRandom = 12; maxTrials = 8; } case INTERMEDIATE -> { maxRandom = 15; maxTrials = 6; } case EXPERT -> { maxRandom = 20; maxTrials = 5; } } final int NOT_GOOD = -1; ArrayList scores = new ArrayList(); boolean playAgain; do { playAgain = false; int randomNum = random.nextInt(maxRandom + 1); int trials = maxTrials; String strNum = ""; boolean numberFound = false; while (trials > 0) { System.out.print(" Guess the number ( Hint: Your number is less than the hidden number!"); } else if (num > randomNum) { System.out.println("-> Hint: Your number is greater than the hidden number!"); } else { numberFound = true; break; } --trials; } } if (numberFound) { System.out.println("-> You have correctly guessed teh number !"); scores.add(new GameScore(maxTrials - trials, true)); } else { System.out.println("-> You failed to guess the number! The number was " + randomNum); scores.add(new GameScore(maxTrials, false)); } System.out.print(" Do you want to play again (y): "); char ch = keyboard.nextLine().trim().charAt(0); if (ch == 'y' || ch == 'Y') { playAgain = true; } } while (playAgain); double avg = 0; System.out.println(" ------------- Results -------------"); System.out.println("Name: " + name); System.out.println("Level: " + level); System.out.printf("%-10s %-15s %s ", "Game No", "Number of Tries", "Result"); for (int i = 0; i  

Package Explorer X "GameScore.java > Assignment 1 package code; ed classes public class GameScore { GameScore public int trials; EJRE Systern Library (Java SE 15.0.2 (16.0. 5 public boolean result; SIC Voode 7 70 public GameScore(int trials, boolean result) { 8 D GameScore.java this.trials = trials; 9 this.result = result; > GameScore } } > C Main 11 126 public GameScore() { 13 } 14} 15/********* Main.java *********/ 6 package code: 17 18@import java.util.ArrayList; 19 part lava.util.Random: 20 uport lava.util.Scanner: 21 22 public class Main { 8 23 24 public static int isValid (String strium, int naxNumber) { 25 int num= -1: 26 27 if (strhum != null) { 28 try { 29 num = Integer.parseInt(strnun); 30 if (num maxNumber) 31 num = -1; 32 33 } catch (Number Format Exception nfe) { 34 return nun; 35 } 36 } 37 return num; 38 } 39 40 public static void main(String[] args) { 41 42 // Random values generator 43 Random randon = new Random(); 44

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions