Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.util.Scanner; import java.util.ArrayList; import java.io . ByteArrayOutputStream; import java.io . PrintStream; public class DataVisualizer { private final String title; private final String authorNameColumn; private
import java.util.Scanner;
import java.util.ArrayList;
import java.ioByteArrayOutputStream;
import java.ioPrintStream;
public class DataVisualizer
private final String title;
private final String authorNameColumn;
private final String numNovelsColumn;
private final ArrayList dataPoints;
public DataVisualizerString title, String authorNameColumn, String numNovelsColumn
this.title title;
this.authorNameColumn authorNameColumn;
this.numNovelsColumn numNovelsColumn;
this.dataPoints new ArrayList;
public static void mainString args
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;
boolean done false;
do
System.out.printlnEnter a data point Enter to stop input:;
String input scanner.nextLine;
if inputequals
done true;
else
try
if input.contains
throw new ExceptionError: No comma in string.
;
if inputlastIndexOf input.indexOf
throw new ExceptionError: Too many commas in input.
;
String dataArray input.split;
String author dataArraytrim;
int novelQty Integer.parseIntdataArraytrim;
System.out.printlnData string:: author;
System.out.printlnData interger: novelQty"
;
;
dvdataPoints.addnew DataPointauthor novelQty;
catch NumberFormatException nfe
System.out.printlnError: Comma not followed by an integer.
;
catch Exception 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.printfsd
dauthor, dnovelQty;
private void printHistogram
for DataPoint d : dataPoints
System.out.printfs dauthor;
for int i ; i dnovelQty; i
System.out.print;
System.out.println;
@Override
public String toString
ByteArrayOutputStream os new ByteArrayOutputStream;
PrintStream standardOut System.out;
PrintStream stringOut new PrintStreamos;
System.setOutstringOut;
printTable;
System.out.println;
printHistogram;
System.out.flush;
System.setOutstandardOut;
return ostoString;
private static class DataPoint
private final String author;
private final int novelQty;
public DataPointString author, int novelQty
this.author author;
this.novelQty novelQty;
can anyone help me fix my eroors
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