Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; /* * A class used in displaying a bar chart where the bars are drawn vertically using text characters

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
/*
* A class used in displaying a bar chart where the bars are drawn vertically using text characters to repsent bar height
*/
public class VerticalBar
{
String label;
int height;

public VerticalBar(String label, int h)
{
this.label  = label;
this.height = h;
}

public String getLabel()
{
return label;
}

public void setLabel(String label)
{
this.label = label;
}

public int getHeight()
{
return height;
}

public void setHeight(int height)
{
this.height = height;
}

/*
 * Output a vertical bar as an array list of strings where the 0th element in the array list is the label, the
 * 1st element in the array list is the string "-" and each subsequent element is the string "X" where the
 * number of these subsequent elements is equal to the height of this bar
 */
public ArrayList output()
{
//-----------Start below here. To do: approximate lines of code = 6
//






//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
}




part b:

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
/*
*
* This class simulates a bar chart using text. A bar chart consists of a list of VerticalBar objects.
* Each VerticalBar object has a label and an integer height  
*/
public class VerticalBarChart
{
ArrayList  barChart = new ArrayList();
static final int MAXHEIGHT = 11;

public void addVerticalBar(VerticalBar bar)
{
//-----------Start below here. To do: approximate lines of code = 1
// Add the VerticalBar object bar to the barChart

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
// Print the bar chart
void printChart()
{
//-----------Start below here. To do: approximate lines of code = 10
// print the vertical bar chart. Hint: use  a nested loop. Outer loop is the number of rows
// using the MAXHEIGHT constant as the max number of rows. The inner loop loops over the VerticalBar
// objects from the barChart array list and for each one, gets the output array list (see class VerticalBar).
// Print out the row entry (if it exists in the array list, otherwise print a " "). Then print another " " unless this
// is the last VerticalBar.  


//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

// Sort the VerticalBar objects in the barChart by height (smallest to largest)
void sortVerticalBarsByHeight()
{
//-----------Start below here. To do: approximate lines of code = 1
//

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
// Create a helper class HeightComparator that implements the Comparator interface
// and compares two VerticalBar objects based on their height (smallest to largest)
//-----------Start below here. To do: approximate lines of code = 3
//







//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

//Sort the VerticalBar objects in the barChart by label
void sortVerticalBarsByLabel()
{
//-----------Start below here. To do: approximate lines of code = 1
//

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
// Create a helper class LabelComparator that implements the Comparator interface
// and compares two VerticalBar objects based on their labels
//-----------Start below here. To do: approximate lines of code = 3
//







//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

Step by Step Solution

3.34 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

VerticalBarjava import javautilArrayList import javautilCollections import javautilComparator A class used in displaying a bar chart where the bars are drawn vertically using text characters to repsen... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Document Format ( 2 attachments)

PDF file Icon
608c00a382223_208358.pdf

180 KBs PDF File

Word file Icon
608c00a382223_208358.docx

120 KBs Word File

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business research methods

Authors: William G Zikmund, Barry J. Babin, Jon C. Carr, Mitch Griff

8th Edition

978-032432062, 0324320620, 1439080674, 978-1439080672

More Books

Students also viewed these Programming questions

Question

Why does the aggregate demand curve slope downward?

Answered: 1 week ago

Question

What does show(p) do?

Answered: 1 week ago

Question

=+a. Interpret the coefficients of x1 and x2 in the given equation.

Answered: 1 week ago

Question

2.1 Identify the parts of the neuron and describe their functions.

Answered: 1 week ago