Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

. Character-based Histogram Carefully read this entire document before beginning your work 1.Objectives learn Java syntax display to the terminal for loops static methods with

. Character-based Histogram

Carefully read this entire document before beginning your work

1.Objectives

learn Java syntax

display to the terminal

for loops

static methods with parameters and returns

overloaded methods

The voter participation data we will work with is stored in a Word document Presidential Elections.docx or you can find on http://www.sos.wa.gov/elections/voter_participation.aspx.

Its expected that you hard code the bar data in the main() method, i.e., I expect to see the corresponding values typed into your program and passed to the functions as arguments. Outside of this, you should have no magic numbers; use values from the website instead.

2.Constants Definition

For this program, gather no input from the user. Instead, define constants to hold key data, making it easy to change the values to test your program.

Define at least these constants to hold general histogram settings:

Constant

Description

Sample

Histogram title

Text that will appear centered (over a 80-character space) before the histogram is displayed. One blank line follows it.

"Presidential Elections"

Histogram characters

The character to be repeated to create the data bar

T, R, V

Scale

Use a scale for the chart to create bars in the appropriate size

100,000

Step

Use a step for the chart to create axis

1,000,000

3.Output

The output of the program is a character-based histogram showing some bars of data taking from the website. Use at least 5 different years. The header should be in the center of the first line.

Dont hardcode numbers, e.g., for the axis values. In other words, dont have a print statement that prints a string literal 5000 10000 15000 ; write a proper loop instead and use steps and scales. The same goes for tick marks.

You dont need to make the number range flexible; see the top values in the file.

Also, you dont need to guard against bad data. But you should test your program with values that are in the specified ranges that should work.

Sample:

Presidential Elections

2000 |TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT |RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR |VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV | 2004 |TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT |RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR |VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV | 2008 |TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT |RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR |VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV | 2012 |TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT |RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR | VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV | 2016 |TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT |RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR |VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV |------------+------------+------------+------------+------------+------------+ 0 1000000 2000000 3000000 4000000 5000000 6000000

4.Calculations

There are no special calculations. Do the ones you need to create the desired output in the printHeader() method. You may wish to use the String length method; this one is allowed.

Example:

String userName = "Any Name";

int userNameLen = userName.length();

5.Code Implementation

Create a class called Histogram. Follow the provided Course Style Guide.

5.1 Hierarchy

Create the following static functions. Use this exact call hierarchy:

main() should consist of a series of function calls and nothing more

printHeader() should accept one parameter the name of the chart

createBar() will be an overloaded method

the firsts variant should accept four parameters:

an integer specifying the bar title (the year)

an integer indicating the bar value

the character to be repeated to create the data bar

the scale

the second variant accepts three parameters, the same as the first but excluding the year.

createAxis() should accept one parameter a step

emptyRow() should accept no parameters

None of the functions should return any value

5.2 What You May Use

Constants (at class level), using the recommended casing and word separator

Variables (but not class-level ones)

Assignment and calculations

Definite loops

Console output

5.3 What You May Not Use

Indefinite loops (no while)

Selection control structures (no if) unless youre doing something way above and beyond

Arrays, lists, or other data structures or objects we havent covered

Libraries or methods we havent covered

6.Submitting Your Work

Submit the .jar file from your homework or zip up the entire folder.

7.Other Requirements

Your design must use procedural decomposition.

Use class constants where appropriate.

The program must start with main().

Your file must have a program comment at the top. This description, at a minimum, is one to two lines explaining what the program does.

Include your name and date in the file comments.

Each method must include a block comment that describes what the method does a description of parameters (if there are any) what is returned (if anything is returned)

In addition to the block comments, also include algorithm comments, that help to explain your algorithms.

Use good style, such as good variable and method names, class constants, appropriate indentation, etc

9.Extra Credit (5 points)

Add to your project additional information

Percentage of Voting Age Population Registered

Percent of Voting Age Population Voting

Dont copy this information from the site, you should calculate it and compare your result to the website. Create a new method that accepts parameters and print the result as follows:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

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

More Books

Students also viewed these Databases questions

Question

When is it appropriate to use a root cause analysis

Answered: 1 week ago