Advertisement
mmayoub

java-Exercise05-final course grade

Jun 21st, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. package class170619;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class tester05 {
  6.  
  7.     public static void main(String[] args) {
  8.         /*
  9.          * בהינתן ציון המבחן של הסטודנט (X), מספר המטלות שהוגשו (N) וממוצע
  10.          * המטלות שהוגשו (Y), יש לחשב את ציונו הסופי של הסטודנט
  11.          */
  12.  
  13.         int testGrade; // input: grade of the test
  14.         int tasksNo; // input: number of tasks
  15.         double tasksAverage; // input: average grade for home work tasks
  16.         double finalGrade; // output: final grade for the course
  17.  
  18.         // create a scanner to get input data
  19.         Scanner s = new Scanner(System.in);
  20.  
  21.         // get all input data from user and save it to variables
  22.         System.out.println("Enter your test grade (0 to 100): ");
  23.         testGrade = s.nextInt();
  24.         System.out.println("Enter number of home work tasks: ");
  25.         tasksNo = s.nextInt();
  26.         System.out
  27.                 .println("Enter average grade from home work tasks (0 to 100): ");
  28.         tasksAverage = s.nextDouble();
  29.  
  30.         s.close();
  31.  
  32.         // calculate final grade
  33.         switch (tasksNo) {
  34.         case 0:
  35.         case 1:
  36.         case 2:
  37.         case 3:
  38.         case 4:
  39.             finalGrade = testGrade;
  40.             break;
  41.         case 5:
  42.         case 6:
  43.         case 7:
  44.             finalGrade = testGrade >= 60 ? 0.8 * testGrade + 0.2 * tasksAverage
  45.                     : 0.9 * testGrade + .01 * tasksAverage;
  46.             break;
  47.         default:
  48.             finalGrade = testGrade >= 60 ? 0.7 * testGrade + 0.3 * tasksAverage
  49.                     : 0.6 * testGrade + 0.4 * tasksAverage;
  50.             break;
  51.         }
  52.  
  53.         // print final grade to screen, with one digit after the point
  54.         System.out.printf("your final grade is: %.1f", finalGrade);
  55.  
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement