Question

Write a Java program that will read in this XLS file and store them in an ArrayList or LinkedList or HashMap

Ask user to input what country they wish to search for and then output the country population.

Also ask user which other countries they wish to compare. then compare the two countries by outputting both country population

NOTE: THIS IS AN XLS FILE

F9 Population 1 Country 2 31056997 3581655 32930091 57794 71201 12127071 13477 69108 39921833 2976372 71891 20264082 8192880 7961619 303770 698585 3 Afghanistan 4 Albania 5 Algeria 6 American Samoa 7 Andorra 8 Angola 9 Anguilla 10 Antigua & Barbuda 11 Argentina 12 Armenia 13 Aruba 14 Australia 15 Austria 16 Azerbaijan 17 Bahamas, The 18 Bahrain 19 Bangladesh 20 Barbados 21 Belarus 22 Belgium 23 Belize 24 Benin 147365352 279912 10293011 10379067 287730 7862944 65773 2279723 8989046 4498976 1639833 188078227 23098 379444 7385367 13902972 47382633 25 Bermuda 26 Bhutan 27 Bolivia 28 Bosnia & Herzegovina 29 Botswana 30 Brazil 31 British Virgin Is 32 Brunei 33 Bulgaria 34 Burkina Faso 35 Burma 36 Burundi 37 Cambodia 38 Cameroon 39 Canada 13881427 17340702 33098932

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.sql.Date;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

import java.util.Set;

import java.util.Scanner;

import org.apache.poi.ss.usermodel.Row;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

importorg.apache.poi.xssf.usermodel.XSSFSheet;

public class XLSReader {

public static void main(String[] args) {

                   int arr[][]= new int[100][2];

                   int i=0,j;

                  

try {

File excel = new File("C://user/Country.xls");

FileInputStream fis = new FileInputStream(excel);

XSSFWorkbook book =new XSSFWorkbook(fis);

XSSFSheet sheet = book.getSheetAt(0);

Iterator<Row> itr = sheet.iterator();

// Iterating over Excel file in Java

while (itr.hasNext()) {

Row row = itr.next();

Iterator<Cell> cellIterator = row.cellIterator();

while (cellIterator.hasNext()) {

  Cell cell = cellIterator.next();

switch (cell.getCellType()) {

     case Cell.CELL_TYPE_STRING:              a[i][1]=cell.getStringCellValue();

break;

   case Cell.CELL_TYPE_NUMERIC:

          a[i][2]=cell.getNumericCellValue();

          break;

}

i++;

                 }

       }

book.close();

Scanner scan = new Scanner(System.in);

System.out.print(“Enter the name of the country”);

          String s=scan.nextLine();

for(j=0;j<i;j++)

if(s.compareTo(a[i][1]==0)

System.out.println(“ Population is” + a[i][2]);

  }

  }
}

Add a comment
Know the answer?
Add Answer to:
Write a Java program that will read in this XLS file and store them in an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Carbon dioxide (CO2) emissions are widely believed to be a driver of global climate change. In...

    Carbon dioxide (CO2) emissions are widely believed to be a driver of global climate change. In this problem set you will use cross-section data to test what drives countries’ “carbon footprints,” that is, their CO2 emissions. Is it population, or is income the bigger culprit? The data set “CO2 by country 2010 sh S17” contains data on a sample of countries’ CO2 emissions, in kilotons; population, in millions; and gross national income (GNI), in millions of US dollars, for the...

  • Will reward thumbs up 100% if works. thank you Pickling with Python code and Pandas code Do both ...

    Will reward thumbs up 100% if works. thank you Pickling with Python code and Pandas code Do both pickling assignment in one Jupyter Notebook file. Python Pickle steps: Download the CSV file. Load into a Pandas DataFrame. Make the column ‘country’ the index. Print the header. Using Python code, pickle the DataFrame and name the file: PythonPickle. Load back the PythonPickle data into the DataFrame. Print the header. (Note both printed headers should match.) Pandas Pickle steps: Download the CSV...

  • DATA: # happy2.py import csv def main(): happy_dict = make_happy_dict() print_sorted_dictionary(happy_dict) def make_happy_dict(): filename = "happiness.csv"...

    DATA: # happy2.py import csv def main(): happy_dict = make_happy_dict() print_sorted_dictionary(happy_dict) def make_happy_dict(): filename = "happiness.csv" happy_dict={} with open(filename, 'r') as infile: csv_happy = csv.reader(infile) infile.readline() for line in csv_happy: happy_dict[line[0]] = line[2]       return happy_dict def lookup_happiness_by_country(happy_dict): return def print_sorted_dictionary(D): if type(D) != type({}): print("Dictionary not found") return print("Contents of dictionary sorted by key.") print("Key","Value") for key in sorted(D.keys()): print(key, D[key]) main() "happines.csv" Country,Year of Estimate,Happiness Index Afghanistan,2018,2.694303274 Albania,2018,5.004402637 Algeria,2018,5.043086052 Angola,2014,3.794837952 Argentina,2018,5.792796612 Armenia,2018,5.062448502 Australia,2018,7.17699337 Austria,2018,7.396001816 Azerbaijan,2018,5.167995453 Bahrain,2017,6.227320671 Bangladesh,2018,4.499217033...

  • ONLY ANSWER THE QUESTIONS AT THE BOTTOM Case Description Corporations with international operations need to assess...

    ONLY ANSWER THE QUESTIONS AT THE BOTTOM Case Description Corporations with international operations need to assess the risks associated with setting up and maintaining operations in different regions of the world. Consideration of the risks include considering such issues as political and economic stability. One indicator of the healthcare and quality of life in a country or region that is considered correlated with the risk and stability in the region is the child mortality rate. As a result, the healthcare...

  • ONLY ANSWER THE QUESTIONS AT THE BOTTOM Case Description Corporations with international operations need to assess...

    ONLY ANSWER THE QUESTIONS AT THE BOTTOM Case Description Corporations with international operations need to assess the risks associated with setting up and maintaining operations in different regions of the world. Consideration of the risks include considering such issues as political and economic stability. One indicator of the healthcare and quality of life in a country or region that is considered correlated with the risk and stability in the region is the child mortality rate. As a result, the healthcare...

  • 8 AutoSave D The Home Data Review View Help Power Pivot Formulas Insert Draw Page Layout...

    8 AutoSave D The Home Data Review View Help Power Pivot Formulas Insert Draw Page Layout ES - per capita GDP 1 Country Name 2 Central African Republic 3 Myanmar 4 Congo, Dem. Rep. 5 South Sudan 6 Madagascar 7 Burundi 8 Ethiopia 9 Guinea 10 Malawi 11 Niger 12 Gambia, The 13 Bangladesh 14 Guinea-Bissau 15 Lao PDR 16 Benin 17 Pakistan 18 Chad 19 Nepal 20 Mozambique 21 uberia 22 Kenya 23 Senegal 24 Burkina Faso 25 Mauritania...

  • Case Description Corporations with international operations need to assess the risks associated with setting up and...

    Case Description Corporations with international operations need to assess the risks associated with setting up and maintaining operations in different regions of the world. Consideration of the risks include considering such issues as political and economic stability. One indicator of the healthcare and quality of life in a country or region that is considered correlated with the risk and stability in the region is the child mortality rate. As a result, the healthcare and quality of care as measured by...

  • 22 Use data_Americas. Plot year vs gdpPercap. Scale gdpPercap by log10. Color the data by country....

    22 Use data_Americas. Plot year vs gdpPercap. Scale gdpPercap by log10. Color the data by country. 23 Use data_Americas. Plot year vs gdpPercap. Scale gdpPercap by log10. Color the data by country and size by pop. Looking for the answers in R command codes. 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 2002 2007 142 142 142 142 142 142 142 142 142 142 142 142 > table(gapminder$country) Afghanistan Albania Algeria 12 12 12 Angola Argentina Australia 12...

  • 12 Use data_2002. Use ggplot. Plot gdpPercap vs lifeExp. 13 Use data_2002. Use ggplot. Plot gdpPercap...

    12 Use data_2002. Use ggplot. Plot gdpPercap vs lifeExp. 13 Use data_2002. Use ggplot. Plot gdpPercap vs lifeExp by continent (color) 14 Use data_2002. Use ggplot. Plot gdpPercap vs lifeExp by continent and pop (color and size) 15 Get data for Europe in 2002. Call it data_Europe Looking for these problems in R command code answers. 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 2002 2007 142 142 142 142 142 142 142 142 142 142 142 142...

  • Case Description Corporations with international operations need to assess the risks associated with setting up and...

    Case Description Corporations with international operations need to assess the risks associated with setting up and maintaining operations in different regions of the world. Consideration of the risks include considering such issues as political and economic stability. One indicator of the healthcare and quality of life in a country or region that is considered correlated with the risk and stability in the region is the child mortality rate. As a result, the healthcare and quality of care as measured by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT