Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab01.homework;
- // Create a method called displayHighScorePosition
- // it should a players name as a parameter, and a 2nd parameter as a position in the high score table
- // You should display the players name along with a message like " managed to get into position " and the
- // position they got and a further message " on the high score table".
- //
- // Create a 2nd method called calculateHighScorePosition
- // it should be sent one argument only, the player score
- // it should return an int
- // the return data should be
- // 1 if the score is >=1000
- // 2 if the score is >=500 and < 1000
- // 3 if the score is >=100 and < 500
- // 4 in all other cases
- // call both methods and display the results of the following
- // a score of 1500, 900, 400 and 50
- //
- public class Homework {
- public static void main(String[] args) {
- displayHighScorePosition("Phil", calculateHighScorePosition(1500));
- displayHighScorePosition("Brad", calculateHighScorePosition(900));
- displayHighScorePosition("Gary", calculateHighScorePosition(400));
- displayHighScorePosition("Peter", calculateHighScorePosition(50));
- }
- /**
- * Print to stdout: player name and position on the score board.
- * @param name
- * @param position
- */
- static void displayHighScorePosition(String name, int position) {
- System.out.println(name + "managed to get into position " + position + " on the high score board.");
- }
- /**
- * Given a score, return the score board position.
- * @param score
- * @return
- */
- static int calculateHighScorePosition(int score) {
- int ret = 4;
- if (score >= 1000) {
- ret = 1;
- } else if (score >= 500) {
- ret = 2;
- } else if (score >= 100) {
- ret = 3;
- }
- return ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement