Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. package com.aimeeramirez;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. boolean gameOver = true;
  7. int score = 800;
  8. int levelCompleted = 5;
  9. int bonus = 100;
  10.  
  11. int highScore = calculateScore(gameOver, score, levelCompleted, bonus);
  12. System.out.println("Your final score was " + highScore);
  13.  
  14. score = 10000;
  15. levelCompleted = 8;
  16. bonus = 200;
  17.  
  18. highScore = calculateScore(gameOver, score, levelCompleted, bonus);
  19. System.out.println("Your final score was " + highScore);
  20.  
  21. // Create a method called displayHighScorePosition
  22. // it should a players name as a parameter, and a 2nd parameter as a position in the high score table
  23. // You should display the players name along with a message like " managed to get into position " and the
  24. // position they got and a further message " on the high score table".
  25. //
  26. // Create a 2nd method called calculateHighScorePosition
  27. // it should be sent one argument only, the player score
  28. // it should return an in
  29. // the return data should be
  30. // 1 if the score is >=1000
  31. // 2 if the score is >=500 and < 1000
  32. // 3 if the score is >=100 and < 500
  33. // 4 in all other cases
  34. // call both methods and display the results of the following
  35. // a score of 1500, 900, 400 and 50
  36. //
  37.  
  38. int highScorePosition = calculateHighScorePosition(1500);
  39. displayHighScorePosition("Fluffy", highScorePosition);
  40.  
  41. highScorePosition = calculateHighScorePosition(900);
  42. displayHighScorePosition("Gil", highScorePosition);
  43.  
  44. highScorePosition = calculateHighScorePosition(400);
  45. displayHighScorePosition("Mila", highScorePosition);
  46.  
  47. highScorePosition = calculateHighScorePosition(50);
  48. displayHighScorePosition("Aimee", highScorePosition);
  49.  
  50. highScorePosition = calculateHighScorePosition(1000);
  51. displayHighScorePosition("Ales", highScorePosition);
  52.  
  53. highScorePosition = calculateHighScorePosition(500);
  54. displayHighScorePosition("Kris", highScorePosition);
  55.  
  56. highScorePosition = calculateHighScorePosition(100);
  57. displayHighScorePosition("Jun", highScorePosition);
  58. }
  59.  
  60. public static void displayHighScorePosition(String playerName, int highScorePosition) {
  61. System.out.println(playerName + " managed to get into position "
  62. + highScorePosition + " on the high score table");
  63. }
  64.  
  65. public static int calculateHighScorePosition(int playerScore) {
  66.  
  67. // if(playerScore >= 1000) {
  68. // return 1;
  69. // } else if(playerScore >= 500 && playerScore < 1000) {
  70. // return 2;
  71. //} else if(playerScore >= 100 && playerScore < 500) {
  72. // return 3;
  73. // } else {
  74. // return 4;
  75. // }
  76. //}
  77. int position = 4;
  78. if (playerScore >= 1000) {
  79. position = 1;
  80. } else if (playerScore >= 500) {
  81. position = 2;
  82. } else if (playerScore >= 100) {
  83. position = 3;
  84. }
  85. return position;
  86. }
  87. public static int calculateScore(boolean gameOver,int score, int levelCompleted, int bonus) {
  88.  
  89. if(gameOver) {
  90. int finalScore = score + (levelCompleted * bonus);
  91. finalScore += 2000;
  92. return finalScore;
  93. }
  94.  
  95. return -1;
  96.  
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement