borkins

Exam 24-Apr-2016 - 01. Repairing the Tiles

May 16th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. /**
  2.  * Project: Exam_24_April_2016 - created by borkins on 2017-05-14.
  3.  */
  4.  
  5. import java.text.DecimalFormat;
  6. import java.util.Scanner;
  7.  
  8. public class _01_RepairingTiles
  9. {
  10.     public static void main(String[] args)
  11.     {
  12.         Scanner console = new Scanner(System.in);
  13.        
  14.         int areaLength = Integer.parseInt(console.nextLine());
  15.         double tileWidth = Double.parseDouble(console.nextLine());
  16.         double tileLength = Double.parseDouble(console.nextLine());
  17.         int benchWidth = Integer.parseInt(console.nextLine());
  18.         int benchLength = Integer.parseInt(console.nextLine());
  19.        
  20.         int areaToFill = (areaLength * areaLength) - (benchWidth * benchLength);
  21.         double tilesArea = tileWidth * tileLength;
  22.         double tilesNeeded = areaToFill / tilesArea;
  23.         double timeMin = tilesNeeded * 0.2;
  24.        
  25.         System.out.println(doubleToCSharpDouble(tilesNeeded));
  26.         System.out.println(doubleToCSharpDouble(timeMin));
  27.     }
  28.    
  29.     public static String doubleToCSharpDouble(double number)
  30.     {
  31.         StringBuilder sb = new StringBuilder();
  32.         String str = "" + number;
  33.         int len = (str.length() > 16) ? 16 : str.length();
  34.        
  35.         for (int i = 0; i < len; i++)
  36.         {
  37.             if (str.charAt(i) != '.') {
  38.                 sb.append("#");
  39.             }
  40.             else {
  41.                 sb.append(".");
  42.             }
  43.         }
  44.         return new DecimalFormat(sb.toString()).format(number);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment