Advertisement
kaenan

Lab01-Homework

Oct 9th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. package lab01.homework;
  2.  
  3.      // Create a method called displayHighScorePosition
  4.         // it should a players name as a parameter, and a 2nd parameter as a position in the high score table
  5.         // You should display the players name along with a message like " managed to get into position " and the
  6.         // position they got and a further message " on the high score table".
  7.         //
  8.         // Create a 2nd method called calculateHighScorePosition
  9.         // it should be sent one argument only, the player score
  10.         // it should return an int
  11.         // the return data should be
  12.         // 1 if the score is >=1000
  13.         // 2 if the score is >=500 and < 1000
  14.         // 3 if the score is >=100 and < 500
  15.         // 4 in all other cases
  16.         // call both methods and display the results of the following
  17.         // a score of 1500, 900, 400 and 50
  18.         //
  19. public class Homework {
  20.     public static void main(String[] args) {
  21.         displayHighScorePosition("Phil",  calculateHighScorePosition(1500));
  22.         displayHighScorePosition("Brad",  calculateHighScorePosition(900));
  23.         displayHighScorePosition("Gary",  calculateHighScorePosition(400));
  24.         displayHighScorePosition("Peter", calculateHighScorePosition(50));
  25.     }
  26.  
  27.     /**
  28.      * Print to stdout: player name and position on the score board.
  29.      * @param name
  30.      * @param position
  31.      */
  32.     static void displayHighScorePosition(String name, int position) {
  33.         System.out.println(name + "managed to get into position " + position + " on the high score board.");
  34.     }
  35.  
  36.     /**
  37.     * Given a score, return the score board position.
  38.     * @param score
  39.     * @return
  40.     */
  41.     static int calculateHighScorePosition(int score) {
  42.         int ret = 4;
  43.         if (score >= 1000) {
  44.             ret = 1;
  45.         } else if (score >= 500) {
  46.             ret = 2;
  47.         } else if (score >= 100) {
  48.             ret = 3;
  49.         }
  50.         return ret;
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement