Goodiny777

Lesson 2 homework exercise 1-3

Dec 20th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.49 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class lesson_2_homework {
  3.     public static void main(String[] args) {
  4.         Scanner sc = new Scanner(System.in);
  5.  
  6.         // Targil 1
  7.         int rooms, duplex;
  8.         String result ="Wrong amout of rooms!";
  9.         System.out.println("Please enter amount of rooms(3,4 or 5)");
  10.         rooms = sc.nextInt();
  11.         if (rooms==3){result="LeTashlum: 120 nis";}
  12.         else if(rooms==4){result="LeTashlum: 150 nis";}
  13.         else if(rooms==5){
  14.             System.out.println("Is it duplex?(Yes-1, No-0)");
  15.             duplex = sc.nextInt();
  16.             if(duplex==1){result="LeTashlum: 200 nis";}
  17.             else if(duplex==0){result="LeTashlum: 180 nis";}
  18.         }
  19.         System.out.println(result);
  20.  
  21.         //Targil 2
  22.         int price, items, discount_1;
  23.         double discount_2;
  24.         System.out.println("Enter price of items and amount of them separeted by space");
  25.         price = sc.nextInt();
  26.         items = sc.nextInt();
  27.         discount_1 = price - (price / 300) * 50;
  28.         if (items >= 3) {
  29.             discount_2 = price * 0.8;
  30.         } else {
  31.             discount_2 = price;
  32.         }
  33.         if (discount_1 < discount_2) {
  34.             System.out.printf("Price after first discount %d\n", discount_1);
  35.         } else {
  36.             System.out.printf("Price after second discount %f\n", discount_2);
  37.         }
  38.  
  39.         //Targil 3
  40.         int procent_attendance, test_grade, pre_test_grade, homework_grade, result_grade=0;
  41.         System.out.println("Enter procent of student's attendance");
  42.         procent_attendance=sc.nextInt();
  43.         if (procent_attendance<80){ System.out.printf("Final grade: %d\n",result_grade);}
  44.         else {
  45.             System.out.println("Enter a test grade");
  46.             test_grade=sc.nextInt();
  47.             if(test_grade<60){System.out.printf("Final grade: %d\n",result_grade);}
  48.             else {
  49.                 System.out.println("Enter a pre-test grade");
  50.                 pre_test_grade = sc.nextInt();
  51.                 result_grade = test_grade;
  52.                 if (test_grade < pre_test_grade) {
  53.                     result_grade = (int) (test_grade * 0.8 + pre_test_grade * 0.2);
  54.                 }
  55.                 System.out.println("Enter homeworks grade");
  56.                 homework_grade = sc.nextInt();
  57.                 result_grade = (int) (result_grade * 0.9 + homework_grade * 0.1);
  58.                 System.out.printf("Final grade: %d\n",result_grade);
  59.             }
  60.         }
  61.  
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment