import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; /* * A class used in displaying a bar chart where
Question:
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.
}
Business research methods
ISBN: 978-1439080672
8th Edition
Authors: William G Zikmund , Barry J. Babin, Jon C. Carr, Mitch Griff