Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fix this Java program so that it does not show the period symbol before each value that was read in from the excel file. I

Fix this Java program so that it does not show the period symbol before each value that was read in from the excel file. I am reading in an excel file using Apache POI but the output shows a period before every value that was read in. How to remove? Please write a code to remove this and add comments so reading and understanding is easier.

package populationeval;

import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Scanner;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class PopulationEval {

public static void main(String[] args) throws IOException, InvalidFormatException { File excelFile = new File("C:\Users\Assds\Documents\2017census.xlsx"); FileInputStream fis = new FileInputStream(excelFile); XSSFWorkbook myWorkbook = new XSSFWorkbook(excelFile); XSSFSheet mySheet = myWorkbook.getSheetAt(0); Iterator rowIterator = mySheet.iterator(); int selectedRow = 1; HashMap GeographicArea = new HashMap(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); Iterator cellIterator = row.cellIterator(); int selectedColumn = 1; ArrayList yearlyData = new ArrayList(); String geographicName = ""; while(cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch(cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: double num = cell.getNumericCellValue(); if(selectedColumn !=1 && selectedRow >=3) { yearlyData.add(num); }

break; case Cell.CELL_TYPE_STRING: String stringValue = cell.getStringCellValue(); System.out.print(stringValue ); if(selectedRow >= 3 && selectedColumn == 1) { geographicName = stringValue; } if(selectedColumn != 1 && selectedRow >= 3) { yearlyData.add(stringValue); } break; } selectedColumn++; } if(!geographicName.isEmpty()) { GeographicArea.put(geographicName, yearlyData); } System.out.println(); selectedRow++; } //System.out.println(GeographicArea); fis.close(); Scanner input = new Scanner(System.in); System.out.println("Which state would you like to view data for from 2010 to 2017? Use proper spelling."); String user = input.nextLine(); if(GeographicArea.containsKey(user)) { System.out.println("The data from year 2010 to 2017 for " + user + " is: " + GeographicArea.get(user)); } }

}

The picture shows what happens when I run my program. I need to get rid of the period symbols. Thanks.

image text in transcribed

Tur table with row headers in columm A and colmn headers in rous 3 throngh 4. (leading dots indicate sub-parts) .nlabama Alaska .Arizona Arkansas California .Colorado connecticut Delaware District of Columbia Florida Georgia iawaii Idaho llinoi:s Indiana Iowa Kentucky .Louisiana Maine Maryland .Massachusetts Michigan Minnesota .Mississippi Missouri Tur table with row headers in columm A and colmn headers in rous 3 throngh 4. (leading dots indicate sub-parts) .nlabama Alaska .Arizona Arkansas California .Colorado connecticut Delaware District of Columbia Florida Georgia iawaii Idaho llinoi:s Indiana Iowa Kentucky .Louisiana Maine Maryland .Massachusetts Michigan Minnesota .Mississippi Missouri

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago