0

I am fairly new to programming. . .

I am getting an error with the following code :

public class Main {

public static void main(String[] args) {

    int highScore = calculateScore(true, 800, 5, 100);
    System.out.println("Your final score was " + highScore);


    highScore = calculateScore(true, 10000, 8, 200);
    System.out.println("Your final score was " + highScore);

    displayHighScore(Jack, 3);
}

public static int calculateScore(boolean gameOver, int score, int levelCompleted, int bonus) {
    if (gameOver) {
        int finalScore = score + (levelCompleted * bonus);
        finalScore += 2000;
        return finalScore;
    }
    return -1;
}

public static void displayHighScore(String playersName, int position){
    System.out.println(playersName + " managed to get to position " + position);
   }  }
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
C.Bell
  • 37
  • 7

2 Answers2

1

we dont have enough information but inspecting the error msg

Error:(14, 26) java: incompatible types: int cannot be converted to java.lang.String

it looks like the problem is about HOW you are calling the method you wrote...

you are passing an integer where a string must be passed...

look at the signature and give as parameter exactly what the method needs...

a String and an int

public static void main(String[] args) {
    displayHighScore(2, 1);  // for example this is a wrong paramerer error
    displayHighScore("C. Bryan", 1);  // this is ok!

}

public static void displayHighScore(String playersName, int position) {
    System.out.println(playersName + " managed to get to position " + position);

}
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
-8

Try changing to:

System.out.println(playersName + " managed to get to position " + position.toString());

Java doesn't coalesce to string -- you have to do it yourself.

daf
  • 1,289
  • 11
  • 16