BubaLazi

p02_Pets

Mar 15th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Integer;
  3.  
  4. public class Pets {
  5.     public static void main(String[] args) {
  6.         Scanner console = new Scanner(System.in);
  7.  
  8.         int daysAway = Integer.parseInt(console.nextLine());
  9.         int foodLeftInKilos = Integer.parseInt(console.nextLine());
  10.  
  11.         double dogsFoodKgDay = Double.parseDouble(console.nextLine());
  12.         double catsFoodKgDay = Double.parseDouble(console.nextLine());
  13.         double turtleFoodGrDay = Double.parseDouble(console.nextLine());
  14.  
  15.         double dogsFood = dogsFoodKgDay * daysAway;
  16.         double catsFood = catsFoodKgDay * daysAway;
  17.         double turtlesFood= (turtleFoodGrDay * daysAway) / 1000;
  18.  
  19.         double allAnimalsFood = dogsFood + catsFood + turtlesFood;
  20.         double enoughtFood = foodLeftInKilos - allAnimalsFood;
  21.  
  22.  
  23.         if( enoughtFood >= 0){
  24.             enoughtFood = Math.floor(enoughtFood);
  25.             System.out.println((int)enoughtFood + " kilos of food left.");
  26.         }else if (enoughtFood < 0 ){
  27.             enoughtFood = Math.abs(enoughtFood);
  28.             enoughtFood = Math.ceil(enoughtFood);
  29.             System.out.println((int)enoughtFood + " more kilos of food are needed.");
  30.         }
  31.  
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment