Facebook
From Cobalt Motmot, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 190
  1. package Dev;
  2.  
  3. import java.io.*;
  4. import java.util.Scanner;
  5. import java.text.DecimalFormat;
  6.  
  7. public class bmi {
  8.    
  9.     public static void main(String[] args) throws IOException {
  10.        
  11.         //////////////// FILE /////////////////////////////////
  12.         File file = new File("C:\Users\Jacek\Documents\NetBeansProjects\Projekt_WSTI 24.05\src\Dev\Plik.txt");
  13.                
  14.         //////////////// SCANNER /////////////////////////////////
  15.         Scanner scanner = new Scanner(file);
  16.         scanner.useDelimiter("-|\n");
  17.             while(scanner.hasNext()) {
  18.            
  19.              String imie = scanner.next();
  20.              String plec = scanner.next();
  21.              double waga = Double.parseDouble(scanner.next());
  22.              double wzrost = Double.parseDouble(scanner.next());
  23.              
  24.              double bmi = waga/(Math.pow(wzrost, 2));
  25.              
  26.              String fileName = null;
  27.              if(bmi<18.5) {
  28.                 fileName = new String("niedowaga");
  29.                 BufferedWriter bw = new BufferedWriter(new FileWriter(fileName + ".bin", true));
  30.  
  31.                 bw.write(imie);
  32.                 bw.newLine();
  33.                 bw.write(String.valueOf(new DecimalFormat("0.0").format(bmi)));
  34.                 bw.newLine();
  35.                 bw.close();
  36.              }
  37.               else if(bmi>25.0) {
  38.                 fileName = new String("nadwaga");
  39.                 BufferedWriter bw = new BufferedWriter(new FileWriter(fileName + ".bin", true));
  40.  
  41.                 bw.write(imie);
  42.                 bw.newLine();
  43.                 bw.write(String.valueOf(new DecimalFormat("0.0").format(bmi)));
  44.                 bw.newLine();
  45.                 bw.close();
  46.                
  47.              }          
  48.                 System.out.println(imie);
  49.                 System.out.println(new DecimalFormat("0.0").format(bmi));
  50.             }  
  51.     }  
  52. }