Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me fix this error on my code, I do not know what I am doing wrong. Here is my code: import java.util.*; public

Please help me fix this error on my code, I do not know what I am doing wrong.

image text in transcribed

Here is my code:

import java.util.*; public class MatchingGameCorona { public static void Main(String[] args) { Scanner kb = new Scanner(System.in); String answer = ""; Random rand = new Random(); while (!answer.equalsIgnoreCase("q")) { description(); System.out.println(" What is your name:"); String name = kb.nextLine(); System.out.println(" Hello "+name+" lets start playing"); play(rand); System.out.print("Hit enter to let another person play or enter Q to quit: "); answer = kb.nextLine(); } System.out.println("Good Bye!"); } public static int getRand(Random rand, int max) { int randomNum = 1 + rand.nextInt((9 - 1) + 1); return randomNum; } public static void play(Random rand) { Scanner kb = new Scanner(System.in); int total = 0; String answer = ""; int n1= 0, n2 = 0, n3 = 0; while(!answer.equalsIgnoreCase("q")) { n1 = getRand(rand); n2 = getRand(rand); n3 = getRand(rand); System.out.println("You got:"+n1+" "+n2+" "+n3); int match = match(n1, n2, n3); if (match == 2) { total = total + 200; System.out.println("You got two matches, you won 200 dollars"); System.out.print(" Hit enter to continue or press q/Q to quit"); answer = kb.nextLine(); } else if( match == 3) { total = total + 500; System.out.print("You got three matches, you won 500 dollars"); System.out.print(" Hit enter to continue or press q/Q to quit"); answer = kb.nextLine(); } else System.out.println("Sorry no match"); System.out.print(" Hit enter to continue or press q/Q to quit "); answer = kb.nextLine(); } System.out.println(" Total amount you won: " + total); System.out.println(" "); } public static int match(int n1, int n2, int n3) { if(n1==n2 && n2==n3){ return 3; } else if(n1==n2 || n2==n3 ||n1==n3 ){ return 2; } else{ return 0; } } public static void description() { System.out.println("Welcome to number matching game. I will generate three random numbers for you. If two of the numbers match you win 100, if you get three matching numbers you get 300 dollars"); } }

---jGRASP exec: javac -g MatchingGameCorona.java MatchingGameCorona.java:48: error: method getRand in class MatchingGameCorona cannot be applied to given types

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions