Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; import java.util.ArrayList; import java.util.PrintStream; import java.io . ByteArrayOutputStream; public class DataVisualizer { private final String title; private final String authorNameColumn; private final String

import java.util.Scanner;
import java.util.ArrayList;
import java.util.PrintStream;
import java.io.ByteArrayOutputStream;
public class DataVisualizer {
private final String title;
private final String authorNameColumn;
private final String numNovelsIsColumn;
private final ArrayList dataPoints;
public DataVisualizer(String t, String h1, String h2)
Public static void main(String[] args){
String author;
String[] dataArray;
boolean done = false;
String input;
Int novelQty;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a title for the data:");
String title = scanner.nextLine();
System.out.println("you entered: "+ title +"
");
System.out.println("Enter the column 1 header:");
String c1Header = scanner.nextLine();
System.out.println("you entered: "+ c1Header +"
");
System.out.println("Enter the column 2 header:");
String c2Header = scanner.nextLine();
System.out.println("you entered: "+ c2Header +"
");
DataVisualizer dv = new DataVisualizer(title, c1Header, c2Header);
do {
System.out.println("Enter a data point (-1 to stop input):")
input = scanner.nextLine();
if (input.equals("-1)){
done = true:
} else {
try {
if (!input.contains(","))
throw new Exception ("Error: no comma in string.
");
if (input.lastIndexOf(",")> input.indexOf(","))
throw me Exception ("Error: Too many commas in input.
");
dataArray = input.split(",");
author = dataArray[0].trim();
novelQTy = Interger.parseInt(dataArray[1].trim());
System.out.println("Data string: "+ author);
System.out.println("Data integer: "+ novelQty +"
")
da.dataPoints.add(new DataPoint(author, novelQty));
} catch (NumberFormatException nfe){
System.out.println("Error: Comma not followed by an integer.
");
} catch (Execption e){
System.out.println(e.getMessage());
}
}
} while (!done);
System.out.println(dv);
private void printTable(){
System.out.printf("
%33s
", title);
System.out.printf("%-20s|%23s
", authorNameColumn, numNovelsColumn);
System.out.println("-------------------");
for (DataPoint d : dataPoints){
System.out.printf("%-20s|%23s
", d.author, d,novelQty);
}
}
/* Type your code here. */
}
}
private void printHistogram(){
for (DataPoint d : dataPoints){
System.out.printf("%20s ", d.author);
for (int i =0; i d.novelQty; i++){
System.out.print("*");
}
System.out.println();
}
}
public String toString(){
ByteArrayOutputStream os = new ByteArrayOutputStream();
printStream standardOut = System.out;
PrintStream stringOut = new PrintStream(os);
System.setOut = new PrintStream(os);
System.setOut(stringOut);
printTable();
System.out.println();
printHistogram();
System.out.println();
System.out.flush();
System.out.setOut(standardOut);
return os.toString();
}
} can anyone help correct my code
image text in transcribed

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

Dont smell (i.e., too much perfume/cologne).

Answered: 1 week ago

Question

What is Larmors formula? Explain with a suitable example.

Answered: 1 week ago

Question

2 What are the steps that can aid effective communication?

Answered: 1 week ago