Answered step by step
Verified Expert Solution
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.ioByteArrayOutputStream;
public class DataVisualizer
private final String title;
private final String authorNameColumn;
private final String numNovelsIsColumn;
private final ArrayList dataPoints;
public DataVisualizerString t String h String h
Public static void mainString args
String author;
String dataArray;
boolean done false;
String input;
Int novelQty;
Scanner scanner new ScannerSystemin;
System.out.printlnEnter a title for the data:";
String title scanner.nextLine;
System.out.printlnyou entered: title
;
System.out.printlnEnter the column header:";
String cHeader scanner.nextLine;
System.out.printlnyou entered: cHeader
;
System.out.printlnEnter the column header:";
String cHeader scanner.nextLine;
System.out.printlnyou entered: cHeader
;
DataVisualizer dv new DataVisualizertitle cHeader, cHeader;
do
System.out.printlnEnter a data point to stop input:
input scanner.nextLine;
if inputequals
done true:
else
try
if input.contains
throw new Exception Error: no comma in string.
;
if inputlastIndexOf input.indexOf
throw me Exception Error: Too many commas in input.
;
dataArray input.split;
author dataArraytrim;
novelQTy Interger.parseIntdataArraytrim;
System.out.printlnData string: author;
System.out.printlnData integer: novelQty
dadataPoints.addnew DataPointauthor novelQty;
catch NumberFormatException nfe
System.out.printlnError: Comma not followed by an integer.
;
catch Execption e
System.out.printlnegetMessage;
while done;
System.out.printlndv;
private void printTable
System.out.printf
s
title;
System.out.printfss
authorNameColumn, numNovelsColumn;
System.out.println;
for DataPoint d : dataPoints
System.out.printfss
dauthor, dnovelQty;
Type your code here.
private void printHistogram
for DataPoint d : dataPoints
System.out.printfs dauthor;
for int i ; i dnovelQty; i
System.out.print;
System.out.println;
public String toString
ByteArrayOutputStream os new ByteArrayOutputStream;
printStream standardOut System.out;
PrintStream stringOut new PrintStreamos;
System.setOut new PrintStreamos;
System.setOutstringOut;
printTable;
System.out.println;
printHistogram;
System.out.println;
System.out.flush;
System.out.setOutstandardOut;
return ostoString;
can anyone help correct my code
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