Advertisement
tchenkov

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

Feb 24th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 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.        
  27.         BigDecimal talesNeeded = squareAreaWithoutBench.divide(singleTileArea, 30, BigDecimal.ROUND_HALF_UP);
  28.         int talesNeededRoundTo = 15 - (talesNeeded.toPlainString().indexOf('.'));
  29.         BigDecimal finishTime =  talesNeeded.multiply(tileTime);
  30.         int finishTimeRoundTo = 15 - (finishTime.toPlainString().indexOf('.'));
  31.         talesNeeded = talesNeeded.setScale(talesNeededRoundTo, BigDecimal.ROUND_HALF_UP);
  32.         finishTime = finishTime.setScale(finishTimeRoundTo, BigDecimal.ROUND_HALF_UP);
  33.        
  34.        
  35.         System.out.println(df.format(talesNeeded));
  36.         System.out.println(df.format(finishTime));
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement