Currently I'm trying to create a histogram that displays asterisks instead of the numeral. My project is two classes, one for data, and one for display. I feel like I have 90% of this project done except for I can't for the life of me figure out how to print *** instead of 3. Any tips and feedback on my code is greatly appreciated. I really try hard to learn this material and unfortunately for me, it's slow going. I have had success in these forums reading other people's explanations, sometimes people explain things in a manner that is different from what I previously thought and it's a great help. I'm hoping for that again. Here comes some shaky code...My assignment was to create a program that has two classes, uses an ArrayList, uses a loop to process raw data to fill in an Array with the counts, and then use those count values to display a histogram. So, my project is a tool rental center. The ToolRentalDisplay will utilize the Array, and hopefully, the histogram. The ToolRentalData Class has the ArrayList of String values which I chose to make the names of different tools. There is no user input so I made the list of 10 tools (the size of my array) and made the Plate Compactor the most rented tool. Hopefully someone, anyone, can understand what I'm trying to do and help me out. If I didn't, or you have questions, please ask. Thanks everyone.
import java.util.ArrayList; import java.util.Arrays; public class ToolRentalDisplay { private ArrayList<String> rentalData; private int[] rentalCounts; /** * Constructor for objects of class ToolRentalDisplay */ public ToolRentalDisplay() { ToolRentalData data = new ToolRentalData(); rentalData = data.getData(); analyzeData(); } /** * Review the tools that were rented in a given shift //the reason this documentation looks like this is because through all my testing I've been * Record the counts of each tool individually //doing it was easier to be able to see it right there & I can copy/paste. * rentalCounts[0]: Plate Compactor * rentalCounts[1]: Carpet Cleaner * rentalCounts[2]: Lawn Mower * rentalCounts[3]: Roto-Hammer * rentalCounts[4]: Carpet Cleaner * rentalCounts[5]: Pressure Washer * rentalCounts[6]: Air Coil Siding Nailer * rentalCounts[7]: Plate Compactor * rentalCounts[8]: Plate Compactor * rentalCounts[9]: Hammer Drill */ private void analyzeData() { int[] rentalCounts = new int[10]; for (String rental : rentalData) { if (rental.equals("Plate Compactor")) { rentalCounts[0]++; } else if (rental.equals("Carpet Cleaner")) { rentalCounts[1]++; } else if (rental.equals("Lawn Mower")) { rentalCounts[2]++; } else if (rental.equals("Roto-Hammer")) { rentalCounts[3]++; } else if (rental.equals("Air Coil Siding Nailer")) { rentalCounts[4]++; } else if (rental.equals("Pressure Washer")) { rentalCounts[5]++; } else if (rental.equals("Air Coil Siding Nailer")) { rentalCounts[6]++; } else if (rental.equals("Plate Compactor")) { rentalCounts[7]++; } else if (rental.equals("Plate Compactor")) { rentalCounts[8]++; } else if (rental.equals("Hammer Drill")) { rentalCounts[9]++; } } } /** * Display the analyzed data as a histogram using asterisks, not numerals */ public void displayData() { System.out.println("Number of times each tool was rented during that shift:"); System.out.println("Plate Compactor: " + rentalCounts[0]); System.out.println("Carpet Cleaner: " + rentalCounts[1]); System.out.println("Pressure Washer: " + rentalCounts[2]); System.out.println("Lawn Mower: " + rentalCounts[3]); System.out.println("Air Coil Siding Nailer: " + rentalCounts[4]); System.out.println("Hammer Drill: " + rentalCounts[5]); } }