Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; import java.util.ArrayList; public class DataVisualizer { private final String title; private final String authorNameColumn; private final String numNovelsColumn; private final ArrayList dataPoints; public

import java.util.Scanner;
import java.util.ArrayList;
public class DataVisualizer {
private final String title;
private final String authorNameColumn;
private final String numNovelsColumn;
private final ArrayList dataPoints;
public DataVisualizer(String title, String authorNameColumn, String numNovelsColumn){
this.title = title;
this.authorNameColumn = authorNameColumn;
this.numNovelsColumn = numNovelsColumn;
this.dataPoints = new ArrayList>();
}
public static void main(String[] args){
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);
boolean done = false;
do {
System.out.println("Enter a data point (Enter 1 to stop input):");
String 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 new Exception("Error: Too many commas in input.");
}
String[] dataArray = input.split(",");
String author = dataArray[0].trim();
int novelQty = Integer.parseInt(dataArray[1].trim());
System.out.println("Data string: "+ author);
System.out.println("Data integer: "+ novelQty);
dv.dataPoints.add(new DataPoint(author, novelQty));
} catch (NumberFormatException nfe){
System.out.println("Error: Comma not followed by an integer.");
} catch (Exception e){
System.out.println(e.getMessage());
}
}
} while (!done);
System.out.println(dv);
}
private void printTable(){
}
private void printHistogram(){
}
@Override
public String toString(){
}
private static class DataPoint {
private final String author;
private final int novelQty;
public DataPoint(String author, int novelQty){
this.author = author;
this.novelQty = novelQty;
}
}
} can anyone help me correct my gramlical errors
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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Employ effective vocal cues Employ effective visual cues

Answered: 1 week ago