'Error "the constructor HighScore(int,int,String)is undefined" ( game = new HighScore((id, score, user); )
when run the code is shown the constructor HighScore(int, int, String)is undefined"
import java.util.Scanner;
public class HighScore{
public static HighScore readGameScore(Scanner sc){
HighScore game;
String user;
int id;
int score;
System.out.print("Enter game user: ");
user=sc.nextLine();
System.out.print("Enter game ID: ");
id=sc.nextInt();
do{
System.out.print("Enter game score: ");
score=sc.nextInt();
if(score<0){
System.out.println("Please enter a valid value. ");
}
}while(score<0);
*game = new HighScore(id, score, user);*
return game;
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
HighScore game;
System.out.println("Enter your game score info!");
game = readGameScore(sc);
System.out.println("You entered: ");
System.out.println(game);
}
}
Solution 1:[1]
So your class has no constructor defined so the compiler produces a default constructor under the hood i.e.
public HighScore(){}
you need one defined like
public HighScore(int id, int score, String user){
......
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Michael |
