Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Good Evening, I need help with this Bar Chart Assignment. ADD METHOD and DRAW METHOD are used in this assignment. Instructions and code are below.
Good Evening, I need help with this Bar Chart Assignment. ADD METHOD and DRAW METHOD are used in this assignment. Instructions and code are below.
Open the BarChart.java file. You need to write code in two different methods: the add method, and the draw method. I have put these two methods at the top of the class for you. There is a lot going on in this class! Don't worry if the rest of the class doesn't make sense, and don't be distracted by the large amount of code in this file. You just need to make 5 changes - let's focus on that. The add Method In the add method, you'll notice three variables created for you: color, name, and value. Perform the following actions: - Add the "color" variable to the "colors" ArrayList (the ArrayList is declared further down in the file - don't worry that you can't see it in this method). - Add the "name" variable to the "names" ArrayList (ditto). - If the "value" variable is 0 or greater, add it to the "values" ArrayList (ditto). - If the "value" variable less than 0 , add 0 to the "values" ArrayList. The draw Method There are two changes to make in the draw method: - You will see a numberOfBars variable declared at the beginning of the method. Currently this variable is set to 0 . Set it to the number of items in the "names" ArrayList. - Inside the if statement, you will see an xmax variable declared. Set this variable to the largest value in the "values" ArrayList. To do this, you will need to loop through the ArrayList and find the largest value. package barchartracerarraylist; import java.awt. Color; import java. awt. Font; import java.util.ArrayList; import java.util.TreeMap; The \{@code Barchart\} class represents a library for drawing static bar chart. It supports adding a bar (with a specified name, value, and category) and drawing all of the bars to the screen using standard draw. The bars are drawn horizontally (in the order in which they are added from top to bottom) and colored according to the category. The name and value of the bar and drawn with the bar. (aathor Kevin Wayne public class BarChart f / * Adds a bar to the bar chart. * The length of a bar is proportional to its value. * The bars are drawn from top to bottom in the order they are added. * All bars from the same category are drawn with the same color. * Qparam name the name of the bar * @param value the value of the bar * @param category the category of bar / public void add (Bar bar) f if (bar.getName() == null) throw new IllegalArgumentexception ( s: "name is null"); if (bar.getCategory() == null) throw new IllegalArgumentexception (s: "category is null"); If ('colorof.containskey (key: bar.getCategory())) \{ colorof.put (key: bar.getCategory(), coLors [colorof.size() : coLors.length]); 3 Color color = colorof.get(key: bar.getCategory ()); String name = bar. getName(); int value = bar.getValue ()Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started