Question: Program: Data visualization (Java): Please help me fix the issues with my current code to match up with the expected Input: Current Code import java.util.Scanner;

Program: Data visualization (Java): Please help me fix the issues with my current code to match up with the expected Input:

Current Code

import java.util.Scanner; import java.util.ArrayList;

public class DataVisualizer { public static void main(String[] args) { /* Type your code here. */ Scanner input = new Scanner(System.in);

//1

System.out.println("Enter a title for the data: ");

String title = input.nextLine();

System.out.println("You entered: "+title);

//2

System.out.println("Enter the column 1 header: ");

String header1 = input.nextLine();

System.out.println("You entered: "+header1);

System.out.println("Enter the column 2 header: ");

String header2 = input.nextLine();

System.out.println("You entered: "+header2);

//3.

ArrayList strList = new ArrayList();

ArrayList intList = new ArrayList();

while(true){

System.out.println("Enter a data point (-1 to stop input): ");

String point = input.nextLine();

if("-1".equalsIgnoreCase(point.trim()))

break;

int index = point.indexOf(',');

// if there is a comma in input

if(index != -1){

String pointStr = point.substring(0, index).trim();

String str = point.substring(index+1).trim();

// if only one comma is in input

if(str.indexOf(',') == -1){

try{

int x = Integer.parseInt(str);

System.out.println("Data string: "+pointStr);

System.out.println("Data integer: "+x);

// adding in list

strList.add(pointStr);

intList.add(x);

}catch(Exception e){

System.out.println("Comma not followed by an integer");

}

}else{

System.out.println("To many commas in input");

}

}else{

System.out.println("No comma in string");

}

}

System.out.println();

System.out.println(title);

System.out.println(header1+"\t|\t"+header2);

for(int i=0; i

System.out.println(strList.get(i)+"\t|\t"+intList.get(i));

} return; } }

My Input VS Expected Input

Program: Data visualization (Java): Please help me fix the issues with my

current code to match up with the expected Input: Current Code import

java.util.Scanner; import java.util.ArrayList; public class DataVisualizer { public static void main(String[] args)

{ /* Type your code here. */ Scanner input = new Scanner(System.in);

//1 System.out.println("Enter a title for the data: "); String title = input.nextLine();

System.out.println("You entered: "+title); //2 System.out.println("Enter the column 1 header: "); String header1

= input.nextLine(); System.out.println("You entered: "+header1); System.out.println("Enter the column 2 header: "); Stringheader2 = input.nextLine(); System.out.println("You entered: "+header2); //3. ArrayList strList = new ArrayList();ArrayList intList = new ArrayList(); while(true){ System.out.println("Enter a data point (-1 tostop input): "); String point = input.nextLine(); if("-1".equalsIgnoreCase(point.trim())) break; int index =

point.indexOf(','); // if there is a comma in input if(index != -1){

String pointStr = point.substring(0, index).trim(); String str = point.substring(index+1).trim(); // if only

one comma is in input if(str.indexOf(',') == -1){ try{ int x =

Integer.parseInt(str); System.out.println("Data string: "+pointStr); System.out.println("Data integer: "+x); // adding in list strList.add(pointStr);

intList.add(x); }catch(Exception e){ System.out.println("Comma not followed by an integer"); } }else{ System.out.println("To

many commas in input"); } }else{ System.out.println("No comma in string"); } }

Thank you in advance for your help in solving where I am missing steps.

1. Compare output Number of Novels Authored blank Input blank Enter a title for the data: Your output correctly starts with You entered: Number of Novels Authored 2. Compare output Number of Novels Authored Author name Input Number of novels Enter a title for the data You entered Number of Novels Authored Enter the column 1 header: You entered Author name Your output starts with Enter the column 2 header You entered: Number of novels En Enter a title for the data: You entered: Number of Novels Authored Enter the column 1 header Expected output starts with You entered: Author name Enter the column 2 header: You entered: Number of novels

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!