Advertisement
Guest User

Frankies Assignmnet (Swear no hardcoding)

a guest
Oct 26th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Scanner;
  4.  
  5. public class Frankie2 {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         String fileName = "haberman.csv";
  10.         File file = new File(fileName);
  11.         try {
  12.             Scanner inputStream = new Scanner(file);
  13.             int counter = 0;
  14.             int[] auxNode = new int[306];
  15.             int[] survTime = new int[306];
  16.             while (inputStream.hasNext()){
  17.  
  18.                 String data = inputStream.next(); //retrieves entire line
  19.                 String[]values = data.split(",");
  20.                 auxNode[counter] = Integer.parseInt(values[2]);
  21.                 survTime[counter] = Integer.parseInt(values[3]);
  22.                 counter++;
  23.             }
  24.            
  25.             for (int i = 0; i < auxNode.length; i++){
  26.                 System.out.println(auxNode[i]);
  27.             }
  28.            
  29.             System.out.println("PENIS");
  30.            
  31.             for (int i = 0; i < survTime.length; i++){
  32.                 System.out.println(survTime[i]);
  33.             }
  34.            
  35.             double sumAuxNodel = 0; //sum of all aux nodes <5
  36.             double sumAuxNodeu = 0; // sum of all aux nodes >5
  37.             double survTimel = 0; //how many survival times <5
  38.             double survTimeu = 0; //how many survival times >5
  39.            
  40.             for (int i = 0; i < survTime.length; i++){
  41.                 if (survTime[i] == 1){
  42.                     sumAuxNodeu += auxNode[i];
  43.                     survTimeu += 1;
  44.                 }
  45.                
  46.                 if (survTime[i] == 2){
  47.                     sumAuxNodel += auxNode[i];
  48.                     survTimel += 1;
  49.                 }
  50.             }
  51.             System.out.println("Average Aux Node of people with a survival time less than 5 years is" + sumAuxNodel/survTimel + "Nodes");
  52.             System.out.println("Average Aux Node of people with a survival time less than 5 years is" + sumAuxNodeu/survTimeu + "Nodes");
  53.            
  54.            
  55.            
  56.             inputStream.close();
  57.         } catch (FileNotFoundException e) {
  58.             // TODO Auto-generated catch block
  59.             e.printStackTrace();
  60.         }
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement