Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package javaapplication6;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class CareOfPuppy02 {
  6.  
  7.     private static int i;
  8.  
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         int days = Integer.parseInt(scanner.nextLine());
  12.         Double food = Double.parseDouble(scanner.nextLine());
  13.         double FoodEatenDog, FoodEatenCat, totalEatenFood, biscuits = 0;
  14.         Double PercentageTotalEatenFood = null, PercentageTotalFoodEatenDog = null, PercentageTotalFoodEatenCat = null;
  15.         for (i = 0; i < days; i++) {
  16.             FoodEatenDog = Integer.parseInt(scanner.nextLine());
  17.             FoodEatenCat = Integer.parseInt(scanner.nextLine());
  18.             totalEatenFood = (FoodEatenDog + FoodEatenCat);
  19.             PercentageTotalEatenFood = (totalEatenFood / food) * 100;
  20.             PercentageTotalFoodEatenDog = (FoodEatenDog / totalEatenFood) * 100;
  21.             PercentageTotalFoodEatenCat = (FoodEatenCat / totalEatenFood) * 100;
  22.             while (days == 3) {
  23.                 biscuits = Math.round((10 * totalEatenFood) / 100);
  24.                 break;
  25.             }
  26.  
  27.         }
  28.         System.out.printf("Total eaten biscuits: %.2f%%.%n", biscuits);
  29.         System.out.printf("%.2f%% of the food has been eaten.%n", PercentageTotalEatenFood);
  30.         System.out.printf("%.2f%% eaten from the dog.%n", PercentageTotalFoodEatenDog);
  31.         System.out.printf("%2f%% eaten from the cat.%n", PercentageTotalFoodEatenCat);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement