hpilo

Chapter3_Logic_Ex7

Dec 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*  ==================================================
  4.       Chapter 3: Logical and conditional expressions
  5.  
  6.                 Ex7: Final grade
  7.     ===================================================
  8. */
  9.  
  10. public class MyProgram {
  11.     public static void main(String[] args) {
  12.  
  13.         //variables
  14.         int testScore;
  15.         int hwAvg;
  16.         int exercises;
  17.         double finalScore,magen;
  18.         Scanner s=new Scanner(System.in);
  19.  
  20.         //user input- make sure valid input
  21.         do {
  22.             System.out.println("Enter test score: (0-100)");
  23.             testScore = s.nextInt();
  24.         }while(testScore<0 || testScore>100);
  25.  
  26.         do {
  27.             System.out.println("Enter hw average: (0-100)");
  28.             hwAvg = s.nextInt();
  29.         }while(hwAvg<0 || hwAvg>100);
  30.  
  31.         do {
  32.             System.out.println("Enter the number of exercises submited: (0-8)");
  33.             exercises = s.nextInt();
  34.         }while(exercises<0 || exercises>8);
  35.  
  36.  
  37.         /*
  38.             ===================================
  39.             calc final score according to data
  40.             ===================================
  41.         */
  42.  
  43.         //student submit 1-4 exercises
  44.         if(exercises<=4)
  45.             finalScore=0;
  46.  
  47.         //student submit 5-6 exercises
  48.         else if(exercises<=6){
  49.  
  50.             if(testScore<55) {  //student failed the test
  51.                 finalScore=testScore;
  52.             }
  53.             else {      //student passed the test → 20% valid
  54.                 finalScore = (0.8 * testScore) + (0.2 * hwAvg);
  55.             }
  56.         }
  57.  
  58.         //student submit 7-8 exercises
  59.         else {
  60.             //student failed the test
  61.             if(testScore<55){
  62.                 if(hwAvg>=80){  //hw average above 80 → 25% magen
  63.                     magen=(0.25*hwAvg)+(0.75*testScore);
  64.                     finalScore= testScore>magen? testScore: magen;
  65.                 }
  66.                 else{   //hw average below 80 → 20% magen
  67.                     magen=(0.2*hwAvg)+(0.8*testScore);
  68.                     finalScore= testScore>magen? testScore: magen;
  69.                 }
  70.             }
  71.  
  72.  
  73.             else{     //student passed the test → 30% magen
  74.                 magen=(0.3*hwAvg)+(0.7*testScore);
  75.                 finalScore= testScore>magen? testScore: magen;
  76.             }
  77.  
  78.         }
  79.         System.out.println("final score: "+finalScore);
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment