48 CHALLENGE 3

 Create a method called displayHighScorePosition.It should a player's name as a parameter, and the 2nd parameter as a position in the high score table. You should display the player's name along with a message like "manage to get into position" and the position they got and a further message "on the high score table".
Create a 2nd method called calculatedHighScorePositon
it should send one argument only, the player score and it should return an int
the return data score should be
1 if the score is.>=1000
2 if score is >=500 and<1000
3 if the score is >=100 and<500
4 if in all other cases call both methods and display the following score of 1500, 900, 400 and 50

Soln:  package com.cnc;
public class Main {
public static void main(String[] args) {
int position = calculatedHighScorePosition(1500);
displayHighScorePosition("Chinmoy",position);

position = calculatedHighScorePosition(900);
displayHighScorePosition("Cybeer",position);

position = calculatedHighScorePosition(150);
displayHighScorePosition("uno",position);

position = calculatedHighScorePosition(50);
displayHighScorePosition("Allien",position);
}
public static void displayHighScorePosition(String name,int position){
int p = position;
String n = name;
System.out.println(n+" managed to get the position "+p+" on the high score table");
}
public static int calculatedHighScorePosition(int score){
if(score>=1000){
return 1;
}
else if(score>=500 && score<1000){
return 2;
}
else if(score>=100 && score<500){
return 3;
}
else{
return 4;
}
}


}


Popular posts from this blog

NUMBER PALINDROME CHALLENGE

ENCAPSULATION CHALLENGE

USER INPUT PRINT ORIGINAL,REVERSE ARRAY AND SORTED ARRAY