TheBulgarianWolf

Padawan Equipment Exercise

Apr 10th, 2020
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SoftUni {
  4.  
  5.    
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.         System.out.print("Enter the amount of money Ivan Cho has: ");
  10.         double money = Double.parseDouble(sc.nextLine());
  11.         System.out.print("Enter the number of students: ");
  12.         int students = Integer.parseInt(sc.nextLine());
  13.         System.out.print("Enter the price of a single lightsabre: ");
  14.         double lightSabrePrice = Double.parseDouble(sc.nextLine());
  15.         System.out.print("Enter the price of a single robe: ");
  16.         double robePrice = Double.parseDouble(sc.nextLine());
  17.         System.out.print("Enter the price of a single belt: ");
  18.         double beltPrice = Double.parseDouble(sc.nextLine());
  19.  
  20.         int freeBelts = students / 6;
  21.        
  22.         double moreLightSabers = Math.ceil(students * 0.1);
  23.        
  24.         double totalPrice = (students + (int) moreLightSabers) * lightSabrePrice
  25.                 + students * robePrice +
  26.                 (students-freeBelts) * beltPrice;
  27.         if(money >= totalPrice){
  28.             System.out.println("The money is enough - it will cost-" + totalPrice + " lv.");
  29.         }
  30.         else{
  31.             System.out.printf("Ivan Cho will need %.2f lv. more.",(totalPrice-money));
  32.         }
  33.  
  34.     }
  35.  
  36. }
Add Comment
Please, Sign In to add comment