Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package class170619;
- import java.util.Scanner;
- public class tester05 {
- public static void main(String[] args) {
- /*
- * בהינתן ציון המבחן של הסטודנט (X), מספר המטלות שהוגשו (N) וממוצע
- * המטלות שהוגשו (Y), יש לחשב את ציונו הסופי של הסטודנט
- */
- int testGrade; // input: grade of the test
- int tasksNo; // input: number of tasks
- double tasksAverage; // input: average grade for home work tasks
- double finalGrade; // output: final grade for the course
- // create a scanner to get input data
- Scanner s = new Scanner(System.in);
- // get all input data from user and save it to variables
- System.out.println("Enter your test grade (0 to 100): ");
- testGrade = s.nextInt();
- System.out.println("Enter number of home work tasks: ");
- tasksNo = s.nextInt();
- System.out
- .println("Enter average grade from home work tasks (0 to 100): ");
- tasksAverage = s.nextDouble();
- s.close();
- // calculate final grade
- switch (tasksNo) {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- finalGrade = testGrade;
- break;
- case 5:
- case 6:
- case 7:
- finalGrade = testGrade >= 60 ? 0.8 * testGrade + 0.2 * tasksAverage
- : 0.9 * testGrade + .01 * tasksAverage;
- break;
- default:
- finalGrade = testGrade >= 60 ? 0.7 * testGrade + 0.3 * tasksAverage
- : 0.6 * testGrade + 0.4 * tasksAverage;
- break;
- }
- // print final grade to screen, with one digit after the point
- System.out.printf("your final grade is: %.1f", finalGrade);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement