Advertisement
ivanov_ivan

GrapeAndRakia - Yani - Different OutputFormats

Mar 26th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GrapeAndRakia {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double vineyardArea = Double.parseDouble(scanner.nextLine());
  7.         double kgGrapePerSquareMeter = Double.parseDouble(scanner.nextLine());
  8.         double wasteGrape = Double.parseDouble(scanner.nextLine());
  9.  
  10.         double kgGrape = (vineyardArea * kgGrapePerSquareMeter) - wasteGrape;
  11.         double grapeForRakia = 45 / 100.0 * kgGrape;
  12.         double litersRakia = grapeForRakia / 7.5;
  13.         double rakiaProfit = litersRakia * 9.80;
  14.         double grapeForSale =  55 / 100.0 * kgGrape;
  15.         double grapeProfit = grapeForSale * 1.50;
  16.  
  17.         System.out.printf("%.2f", rakiaProfit);
  18.         System.out.println();
  19.         System.out.printf("%.2f", grapeProfit);
  20.        
  21.         /* TODO Example 1 using %n - invariant new line placeholder
  22.         System.out.printf("%.2f%n", rakiaProfit);
  23.         System.out.printf("%.2f%n", grapeProfit);
  24.         */
  25.        
  26.         /* TODO Example 2 using println method with String.format parameters
  27.         System.out.println(String.format("%.2f", rakiaProfit));
  28.         System.out.println(String.format("%.2f", grapeProfit));
  29.         */
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement