EmiliaKitkarska

HOMEWORK2

Oct 23rd, 2019
130
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1. Бонус точки
  2. import java.util.Scanner;
  3. class Main {
  4.   public static void main(String[] args) {
  5.     Scanner scan = new Scanner(System.in);
  6.         int number = scanner.nextInt();
  7.         double bonusPoints = 0;
  8.        
  9.  
  10.        
  11.         if (number % 2 == 0) {
  12.             bonusPoints = 1;
  13.         }else if(number % 5 == 0) {
  14.             bonusPoints = 2;
  15.         }
  16.         if (number <= 100) {
  17.             bonusPoints += 5;
  18.         }else if(number > 100 && number < 1000) {
  19.             bonusPoints += number * 0.2;
  20.         }else if(number > 1000) {
  21.             bonusPoints += number * 0.1;
  22.         }
  23.  
  24.  
  25.  
  26.         System.out.println(bonusPoints);
  27.         System.out.println(number + bonusPoints);
  28.   }
  29. }
  30.  
  31.  
  32. 2. Цена за транспорт
  33. import java.util.Scanner;
  34. class Main {
  35.   public static void main(String[] args) {
  36.     Scanner scanner = new Scanner(System.in);
  37.     int distance = Integer.parseInt(scanner.nextLine());
  38.     String dayOrNight = scanner.nextLine();
  39.     double price = 0;
  40.     double taxiRate = 0;
  41.    
  42.     if(dayOrNight.equals("day")){
  43.       taxiRate = 0.79;
  44.     }else if(dayOrNight.equals("night")){
  45.       taxiRate = 0.90;
  46.     }
  47.     if(distance < 20){
  48.       price = 0.70 + (distance * taxiRate);
  49.     }else if (distance < 100){
  50.       price = distance * 0.09;
  51.     }else{
  52.       price = distance * 0.06;
  53.     }
  54.     System.out.println(price);
  55.    
  56.   }
  57.  
  58. }
  59.  
  60. 3. Поспаливата котка Том
  61. import java.util.Scanner;
  62. class Main {
  63.   public static void main(String[] args) {
  64.     Scanner scanner = new Scanner(System.in);
  65.     int holidays = scanner.nextInt();
  66.     int workingDays = 365 - holidays;
  67.     int totalPlayMinutes = workingDays * 63 + holidays * 127;
  68.     double difference = Math.abs(30000 - totalPlayMinutes);
  69.     double hours = difference / 60;
  70.     double minutes = difference % 60;
  71.  
  72.     if (totalPlayMinutes > 30000){
  73.       System.out.println("Tom will run away");
  74.       System.out.printf("%.0f hours and %.0f  minutes more to play",
  75.               Math.floor(hours), Math.floor(minutes));
  76.  
  77.     }else{
  78.       System.out.println("Tom sleeps well");
  79.       System.out.printf("%.0f hours and %.0f minutes less to play",
  80.              Math.floor(hours), Math.floor(minutes));
  81.     }
  82.   }
  83. }
  84.  
  85. 4. Реколта
  86. import java.util.Scanner;
  87. class Main {
  88.   public static void main(String[] args) {
  89.    Scanner scan = new Scanner(System.in);
  90.    int mLoze = scan.nextInt();
  91.    double grapePerMetre = scan.nextDouble();
  92.    int neededWine = scan.nextInt();
  93.    int workers = scan.nextInt();
  94.    double grapeKilos = mLoze * grapePerMetre / 0.4;
  95.    double wineLiter = grapeKilos / 2.5;
  96.  
  97.    if(wineLiter > neededWine){
  98.      double wineLeft = wineLiter - neededWine;
  99.      System.out.printf("Good harvest this year! Total wine: %.0f litters.%n",
  100.               Math.floor(wineLeft));
  101.      System.out.printf("%.0f litters left -> %.0f litters per person",
  102.               Math.ceil(wineLeft), Math.ceil(wineLeft / workers));
  103.    }else{
  104.      System.out.printf("It will be a tough winter! More %.0f litters wine needed.",
  105.               Math.floor(neededWine - wineLiter));
  106.    }
  107.   }
  108. }
  109.  
  110. 5. Фирма
  111. import java.util.Scanner;
  112. class Main {
  113.   public static void main(String[] args) {
  114.     Scanner scan = new Scanner(System.in);
  115.     int hours = scan.nextInt();
  116.     int days = scan.nextInt();
  117.     int workers = scan.nextInt();
  118.  
  119.     double workDays = days * 0.9;
  120.     double extraHours = (workers * 2) * workDays;
  121.     double workHours = (workDays * 8 * workers) + extraHours;
  122.     double totalHours = Math.floor(workHours + extraHours);
  123.  
  124.     if(totalHours > hours){
  125.       System.out.printf("Yes! %.0f hours left.",
  126.               Math.floor(workHours - hours));
  127.     }else{
  128.       System.out.printf("Not enough time! %.0f hours needed.",
  129.               Math.floor(hours - workHours));
  130.     }
  131.   }
  132. }
  133. 6. Тръби в басейн
  134. import java.util.Scanner;
  135. public class Main{
  136.  
  137.     public static void main(String[] args) {
  138.       Scanner scan = new Scanner(System.in);
  139.       int v = scan.nextInt();
  140.       double pipe1 = scan.nextDouble();
  141.       double pipe2 = scan.nextDouble();
  142.       double hours = scan.nextDouble();
  143.       double water = ((pipe1*hours + pipe2*hours)/v)*100;
  144.      
  145.       if (water <= v){
  146.          System.out.printf("The pool is %.0f%% full, pipe1: %.0f%%, pipe2: %.0f%%", water, pipe1/(pipe1+pipe2)*100,
  147.                   pipe2/(pipe1+pipe2)*100);
  148.       }else {
  149.           System.out.printf("For %f hours the pool overflows with %f liters", hours,((pipe1 + pipe2)*hours)-v);
  150.          
  151.       }
  152.    
  153.     }
  154. }
RAW Paste Data