Question
1 .Create two Java program files named Histogram.java and HistogramTester.java. 2.In Histogram.java, implement a class for the Histogram object described below in the test output.
1 .Create two Java program files named Histogram.java and HistogramTester.java.
2.In Histogram.java, implement a class for the Histogram object described below in the test output. Use the HistogramTester.java file to test your object in development. You do not need user input; simply hardcode the values using parameters. For structure, this assignment will leave open what to include as attributes or methods, as long as it has both and they are used properly. Break the problem up into tasks that would be well-suited for a single method.
3.Within the tester, enter some user-entered examples that will give the results of Test Run 1, while Test Run 2 will make use of the Die object.
4.Upon completion, your program should execute exactly like the program test run. Test your program several times with different datasets, to make sure your program works correctly.
Code for Die Object refenced in step 3
import java.util.*; public class Die { //Object attributes private String name; private int numSides; private int currentValue; private Random generator = new Random(); public Die() { this.numSides = 0; this.currentValue = 0; } public Die (int numSides_) { numSides = numSides_; currentValue = 0; } public int getMumSides() { return numSides; } public void getCurrentValue (int currentValue_) { this.currentValue = currentValue_; }
public int roll() { this.currentValue = generator.nextInt(numSides) + 1; return currentValue; } public String toString() { String result=""; result += Integer.toString(currentValue); return result; } }
Output
Test Run1
Name: Rising and falling pattern
Description: Dataset presented by Zeller for CS200, Assignment 2
Reading data...
Raw Data: 1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4
Pass 1 Statistics:
N: 20
Min: 1
Max: 5
Sum: 58
Average: 2.9
Histogram Data:
1 3
2 5
3 5
4 5
5 2
Histogram (vertical column):
1: XXX
2: XXXXX
3: XXXXX
4: XXXXX
5: XX
Histogram (horizontal row):
X X X
X X X
X X X X
X X X X X
X X X X X
1 2 3 4 5 6
Summary Report: Rising and Falling Pattern
N = 20 min = 1 max = 5 sum = 48 avg = 2.9
1 | X X X
2 | X X X X X
3 | X X X X X
4 | X X X X X
5 | X X
---------------
1 2 3 4 5 Number of Occurrences
Dataset provided by Zeller for CS200 Assignment 2
Test Run 2
Name: D6 100 times
Description: A six-sided die is rolled 100 times.
Reading Data...
Raw Data: (omitted due to amount of data)
Data Sample: 10 elements selected at random
1 6 2 1 4 3 4 1 2 4
Pass 1 Statistics:
N: 100
Min: 1
Max: 6
Sum: 345
Avg: 3.45
Histogram data:
1: 16
2: 16
3: 17
4: 16
5: 14
6: 16
Histogram (vertical column):
1: XXXXXXXXXXXXXXXX
2: XXXXXXXXXXXXXXXX
3: XXXXXXXXXXXXXXXXX
4: XXXXXXXXXXXXXXXX
5: XXXXXXXXXXXXXX
6: XXXXXXXXXXXXXXXX
Histogram (horizontal row):
18
17 X
16 X X X X
15 X X X X
14 X X X X X
13 X X X X X
12 X X X X X
11 X X X X X
10 X X X X X
9 X X X X X
8 X X X X X
7 X X X X X
6 X X X X X
5 X X X X X
4 X X X X X
3 X X X X X
2 X X X X X
1 X X X X X
1 2 3 4 5
Summary Report: D6 100 times
N = 1000 min = 1 max = 6 sum = 345 avg = 3.45
1: X X X X X X X X X X X X X X X X
2: X X X X X X X X X X X X X X X X
3: X X X X X X X X X X X X X X X X X
4: X X X X X X X X X X X X X X X X
5: X X X X X X X X X X X X X X
6: X X X X X X X X X X X X X X X X
-----------------------------------------
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 Number of Occurrences
A six-sided die is rolled 100 times.
Output Notes
Use print format statements to line up numbers, for readability.
The vertical column histogram is quite easy and algorithmic, whereas the horizontal is not quite so easy. Clever solutions to the horizontal histogram is available for extra credit and gratitude.
The summary report should display all results calculated from the data, including the histogram.
If printing all of the data is to cumbersome for display purposes (such as thousands of data elements), select 10 at random for a simple display.
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