diff --git a/evenProblems.class b/evenProblems.class index cb1377f..6859d8c 100644 Binary files a/evenProblems.class and b/evenProblems.class differ diff --git a/evenProblems.java b/evenProblems.java index e9eec7c..daf683b 100644 --- a/evenProblems.java +++ b/evenProblems.java @@ -18,6 +18,7 @@ public static void main(String[] args){ ArrayList bmiVals = new ArrayList<>(); ArrayList childrenVals = new ArrayList<>(); ArrayList chargesVals = new ArrayList<>(); + ArrayList smokerVals = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(new FileReader(csvPath))){ line = reader.readLine(); // Skip header line @@ -34,14 +35,17 @@ public static void main(String[] args){ bmiVals.add(Double.parseDouble(values[2])); childrenVals.add(Integer.parseInt(values[3])); chargesVals.add(Double.parseDouble(values[6])); + smokerVals.add(values[4]); + } - System.out.println("Age values: " + calculateValsFromIntegers(ageVals)); - System.out.println("Children values: " + calculateValsFromIntegers(childrenVals)); - System.out.println("BMI values: " + calculateValsFromDoubles(bmiVals)); - System.out.println("Charges values: " + calculateValsFromDoubles(chargesVals)); + // System.out.println("Age values: " + calculateValsFromIntegers(ageVals)); + // System.out.println("Children values: " + calculateValsFromIntegers(childrenVals)); + // System.out.println("BMI values: " + calculateValsFromDoubles(bmiVals)); + // System.out.println("Charges values: " + calculateValsFromDoubles(chargesVals)); - verticalHistogram(bmiVals); + //verticalHistogram(bmiVals); + smokerHistogram(smokerVals); } @@ -234,6 +238,43 @@ public static void verticalHistogram(ArrayList green){ } + //Probelem 6 + public static void smokerHistogram(ArrayList silver){ + TreeMap Tmap = new TreeMap<>(); + + for(String val : silver){ + if(val.equals("yes")){ + val = "Smoker"; + } else { + val = "Non-Smoker"; + } + if(Tmap.containsKey(val)){ + Tmap.put(val, Tmap.get(val) + 1); + } else { + Tmap.put(val, 1); + } + } + + int max = Collections.max(Tmap.values()); + for(int i = max; i > 0; i--){ + for(String key : Tmap.keySet()){ + if(Tmap.get(key) >= i){ + System.out.print(" * \t\t"); + } else { + System.out.print(" "); + } + } + System.out.println(); + } + for(String key : Tmap.keySet()){ + System.out.print(String.format("%s", key)); + System.out.print("\t"); + } + System.out.println(); + + + } + } diff --git a/tempCodeRunnerFile.java b/tempCodeRunnerFile.java deleted file mode 100644 index c837fe5..0000000 --- a/tempCodeRunnerFile.java +++ /dev/null @@ -1,28 +0,0 @@ -//Round the value down to the nearest integer - int intVal = (int) Math.floor(val); - - if(Tmap.containsKey(intVal)){ - Tmap.put(intVal, Tmap.get(intVal) + 1); - } else { - Tmap.put(intVal, 1); - } - } - //Get the max value in the TreeMap - int max = Collections.max(Tmap.values()); - - //Print the histogram - for(int i = max; i > 0; i--){ - for(int key : Tmap.keySet()){ - if(Tmap.get(key) >= i){ - System.out.print(" * "); - } else { - System.out.print(" "); - } - } - System.out.println(); - } - - for(int key : Tmap.keySet()){ - System.out.print(String.format("%2d ", key)); - } - System.out.println(); \ No newline at end of file