samedi 23 juillet 2016

Output is sometimes right and false

I'm writing a java code to write a text file, and I'm printing the output to see if all conditions a correct, there are some cases the output is correct and some incorrect for the same condition. The cases are:

bpup >= 14 => out1 = 0 out 2 = 0

bpdown >= 9 => out1 = 0 out 2 = 1

bpup > 14 and bpdown > 9 => out1 = 1 out2 = 0

bpup > 14 and bpdown > 9 and pulse <60 => out1 = 1 out2 = 1

Here's my code:

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */

package pfetext;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

/**
 *
 * @author user
 */
public class PFEtext {

    /**
     * @param args the command line arguments
     */

    static int i = 10;
    static int out1;
    static int out2;

    public static void main(String[] args) throws IOException {
        // TODO code application logic here
    int bpup;
    int bpdown;
    int pulse;
    int O2;    
         FileWriter fw=new FileWriter("C:\\Users\\user\\Desktop\\pfe.txt"); 
         BufferedWriter bw= new BufferedWriter(fw); 
         do {
         Random p = new Random();
         bpup = p.nextInt(23 - 3) + 3 ;
         bpdown = p.nextInt(17 - 4) + 4 ;
         pulse = p.nextInt(150 - 30) + 30 ;
         O2 = p.nextInt(100 - 40) + 40;

         //Epistaxis
         if(bpup >= 14){
         out1 = 0;
         out2 = 0;
         System.out.println("========== CASE EPISTACSIS ==========");
         System.out.println("BPUP " + bpup + " " + "BPDOWN " + bpdown + " " + "PULSE " + pulse + " " + "OUT1 " + out1 + " " + "OUT2 " + out2);
//         bw.write(bpup + "," + bpdown + "," + pulse + "," + O2 + "," + out1 + "," + out2);
//         bw.newLine();
         }

         //Blackout
         if(bpdown >= 9){
         out1 = 0;
         out2 = 1;
         System.out.println("========== CASE BLACKOUT ==========");
         System.out.println("BPUP " + bpup + " " + "BPDOWN " + bpdown + " " + "PULSE " + pulse + " " + "OUT1 " + out1 + " " + "OUT2 " + out2);
//         bw.write(bpup + "," + bpdown + "," + pulse + "," + O2 + "," + out1 + "," + out2);
//         bw.newLine();
         }

         //Epistaxis and Blackout
         if(bpup >= 14 && bpdown > 9){
         out1 = 1;
         out2 = 0;
         System.out.println("========== CASE EPISTACSIS & BLACKOUT ==========");
         System.out.println("BPUP " + bpup + " " + "BPDOWN " + bpdown + " " + "PULSE " + pulse + " " + "OUT1 " + out1 + " " + "OUT2 " + out2);
//         bw.write(bpup + "," + bpdown + "," + pulse + "," + O2 + "," + out1 + "," + out2);
//         bw.newLine();
         }

         //Numbness
         if(bpup >= 15 && bpdown >= 9 && pulse <= 60){
         out1 = 1;
         out2 = 1;
         System.out.println("========== NUMBNESS ==========");
         System.out.println("BPUP " + bpup + " " + "BPDOWN " + bpdown + " " + "PULSE " + pulse + " " + "OUT1 " + out1 + " " + "OUT2 " + out2);
//         bw.write(bpup + "," + bpdown + "," + pulse + "," + O2 + "," + out1 + "," + out2);
//         bw.newLine();
         } 
         i--;
         }while(i>0);


         bw.write(bpup + "," + bpdown + "," + pulse + "," + O2 + "," + out1 + "," + out2);
         bw.newLine();

         bw.close();      
    }

}

This is the output:

========== CASE BLACKOUT ========== // correct BPUP 9 BPDOWN 12 PULSE 106 OUT1 0 OUT2 1

========== CASE BLACKOUT ========== // correct BPUP 8 BPDOWN 11 PULSE 145 OUT1 0 OUT2 1

========== CASE BLACKOUT ========== //correct BPUP 7 BPDOWN 15 PULSE 103 OUT1 0 OUT2 1

========== CASE BLACKOUT ========== // incorrect should be epistaxis and blackout BPUP 13 BPDOWN 12 PULSE 145 OUT1 0 OUT2 1

========== CASE EPISTACSIS ========== //correct BPUP 18 BPDOWN 7 PULSE 125 OUT1 0 OUT2 0

========== CASE EPISTACSIS ========== // incorrect should be epistaxis and blackout BPUP 18 BPDOWN 11 PULSE 109 OUT1 0 OUT2 0

========== CASE BLACKOUT ========== // incorrect should be epistaxis and blackout BPUP 18 BPDOWN 11 PULSE 109 OUT1 0 OUT2 1

========== CASE EPISTACSIS & BLACKOUT ========== // correct BPUP 18 BPDOWN 11 PULSE 109 OUT1 1 OUT2 0

========== CASE BLACKOUT ========== // correct BPUP 3 BPDOWN 9 PULSE 107 OUT1 0 OUT2 1

========== CASE BLACKOUT ========== //correct BPUP 10 BPDOWN 10 PULSE 114 OUT1 0 OUT2 1

Aucun commentaire:

Enregistrer un commentaire