Question: public class DataVisualizer { / / Main method public static void main ( String [ ] args ) { / / Create an object of
public class DataVisualizer
Main method
public static void mainString args
Create an object of Scanner class
Scanner scan new ScannerSystemin;
Take the title for data
System.out.printlnEnter a title for the data:";
String title scan.nextLine;
System.out.printlnYou entered: title;
System.out.println;
Take the column header
System.out.printlnEnter the column header:";
String header scan.nextLine;
System.out.printlnYou entered: header;
System.out.println;
Take the column header
System.out.printlnEnter the column header:";
String header scan.nextLine;
System.out.printlnYou entered: header;
System.out.println;
Create an array list to store names
ArrayList name new ArrayList;
Create an array list to store number of novels
ArrayList numNovels new ArrayList;
Loop till the user enter to exit
whiletrue
Take the data point to stop input
System.out.printlnEnter a data point to stop input:;
String data scan.nextLine;
If the user enter
ifdataequals
Exit from loop
break;
If user enter data point
else
Split the data point into array of string
String tokens data.split;
If length of strings is
iftokenslength
Print an error message
System.out.printlnError: No comma in string.
;
If length of strings is greater than
else iftokenslength
Print an error message
System.out.printlnError: Too many commas in input.
;
If length of string is
else
Try to convert second part into integer
try
Convert the second string in to number
int count Integer. parseInttokens;
Add name into names list
name.addtokens;
Add number of novels
numNovels.addcount;
Print string & integer
System.out.printlnData string: tokens;
System.out.printlnData integer: tokens;
System.out.println;
If the second string is not integer
catchNumberFormatException e
Print an error message
System.out.printlnError: Comma not followed by an integer.
;
Print title, column & column header
System.out.printfs
title;
System.out.printfss
header header;
System.out.println;
Loop to print each novels name & number of novels
forint i ; i name.size; i
System.out.printfss
name.geti numNovels.geti;
System.out.println;
Loop to print each novels with histigram of number of novels
forint i ; i name.size; i
System.out.printfs name.geti;
forint j ; j numNovels.geti; j
System.out.printf;
System.out.println;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
