Advertisement
jasperlow

Untitled

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