Advertisement
jasperlow

Untitled

Feb 11th, 2020
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. public class Main
  2. {
  3. public static void main(String[] args) {
  4. double markah = 75;
  5. String Gred = "G";
  6. switch ((int) (markah / 10)) { //cast value to int
  7. // match multiple of 10
  8. // eg. 100 is 100/10=10.0, (int)10.0=10
  9. // eg. 95 is 95/10=9.5, (int)9.5=9
  10. // eg. 89 is 89/10=8.9, (int)8.9=8
  11. case 10:
  12. case 9:
  13. Gred = "A+";
  14. break;
  15. case 8:
  16. Gred = "A";
  17. break;
  18. case 7:
  19. switch ((int) (markah % 10 * 2 / 10)) { //cast value to int
  20. // match doubled remainder of 10 division
  21. // eg. 71 is 71%10=1, 1x2=2, (int)2/10=0
  22. // eg. 74 is 74%10=4, 4x2=8, (int)8/10=0
  23. // eg. 75 is 75%10=5, 5x2=10, (int)10/10=1
  24. // eg. 79 is 79%10=9, 9x2=18, (int)18/10=1
  25. case 1:
  26. Gred = "A+"; //75-79
  27. break;
  28. default:
  29. Gred = "B+"; //70-74
  30. }
  31. break;
  32. case 6:
  33. switch ((int) (markah % 10 * 2 / 10)) {
  34. case 1:
  35. Gred = "B"; // 65-69
  36. break;
  37. default:
  38. Gred = "C+"; //60-64
  39. }
  40. break;
  41. case 5:
  42. Gred = "C";
  43. break;
  44. case 4:
  45. switch ((int) (markah % 10 * 2 / 10)) {
  46. case 1:
  47. Gred = "D"; //45-49
  48. break;
  49. default:
  50. Gred = "E"; //40-44
  51. }
  52. break;
  53. default:
  54. Gred = "G";
  55. }
  56. System.out.println(Gred);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement