Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Bathmos2
  5. {
  6.  
  7. public static void main(String[] args)
  8. {
  9. getInput();
  10.  
  11. }
  12. public static void getInput()
  13. {
  14. int x;
  15. Scanner input = new Scanner(System.in);
  16. System.out.println("Give your grade: ");
  17. x = input.nextInt();
  18. int grade = gradeToInt(x);
  19. switch (grade)
  20. {
  21. case 1:
  22. System.out.println("U got an A");
  23. break;
  24. case 2:
  25. System.out.println("U got a B");
  26. break;
  27. case 3:
  28. System.out.println("U got a C");
  29. break;
  30. case 4:
  31. System.out.println("U got a D");
  32. break;
  33. case 5:
  34. System.out.println("U got an F");
  35. break;
  36. case 6:
  37. System.out.println("Invalid entry, please try again");
  38. getInput();
  39. break;
  40. }
  41. }
  42. public static boolean inRange(int value, int min, int max)
  43. {
  44. return (value>=min)&&(value<max);
  45. }
  46.  
  47. public static int gradeToInt(int x)
  48. {
  49. int output = 1;
  50. int[] gradeA = {1, 90, 101};
  51. int[] gradeB = {2, 80, 90};
  52. int[] gradeC = {3, 70, 80};
  53. int[] gradeD = {4, 60, 70};
  54. int[] gradeF = {5, 0, 60};
  55.  
  56.  
  57. int[][] grades = {gradeA,gradeB,gradeC,gradeD,gradeF};
  58.  
  59. int i = 0;
  60. boolean s = false;
  61. try
  62. {
  63. while( s == false)
  64. {
  65. output = grades[i][0];
  66. s = inRange(x, grades[i][1], grades[i][2]);
  67. i = i + 1;
  68. }
  69. return output;
  70. }
  71. catch (IndexOutOfBoundsException e)
  72. {
  73. return 6;
  74. }
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement