Advertisement
tchenkov

Exam 24 April 2016 01. Поправка на плочки v2

Feb 24th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.text.DecimalFormat;
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * Created by todor on 16.02.2017 г..
  7.  */
  8. public class Dummy {
  9.    
  10.     public static void main(String[] args) {
  11.         Scanner scan = new Scanner(System.in);
  12.         int squareAreaSideSize = Integer.parseInt(scan.nextLine());
  13.         double tileWidth = Double.parseDouble(scan.nextLine());
  14.         double tileHeight = Double.parseDouble(scan.nextLine());
  15.         int benchWidth = Integer.parseInt(scan.nextLine());
  16.         int benchHeight = Integer.parseInt(scan.nextLine());
  17.         BigDecimal tileTime = new BigDecimal("0.2");
  18.        
  19.         double benchArea  = benchWidth * benchHeight;
  20.         BigDecimal squareAreaWithoutBench = new BigDecimal(String.valueOf(squareAreaSideSize * squareAreaSideSize - benchArea));
  21.        
  22.         BigDecimal singleTileArea = new BigDecimal(String.valueOf(tileWidth * tileHeight));
  23.        
  24.         DecimalFormat df = new DecimalFormat("#.############");
  25.        
  26.         BigDecimal talesNeeded = squareAreaWithoutBench.divide(singleTileArea, 30, BigDecimal.ROUND_HALF_UP);
  27.         BigDecimal finishTime =  talesNeeded.multiply(tileTime);
  28.         talesNeeded = talesNeeded.setScale(bdLength(talesNeeded, 16), BigDecimal.ROUND_HALF_UP);
  29.         finishTime = finishTime.setScale(bdLength(finishTime, 16), BigDecimal.ROUND_HALF_UP);
  30.                
  31.         System.out.println(df.format(talesNeeded));
  32.         System.out.println(df.format(finishTime));
  33.     }
  34.    
  35.     private static int bdLength(BigDecimal bdNumber, int numberLength) {
  36.         return numberLength - (bdNumber.toPlainString().indexOf('.')) - 1;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement