Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Objectives - learn/practice the following new concepts:
- Input data file with header record and "dirty data"
- Parallel arrays
- Direct address storage algorithm
- User menu & method-selector based on user choice
- Processing arrays as streams
- Calculating stats for a selected subset of data
- Linear search of array - single match & multiple matches

BASIC REQUIREMENTS Same as asgn 4

PROJECT OVERVIEW This project uses data about the countries in the world in order to answer interactive user queries ("questions"). Two main parts to the program. 1st) The input file data needs to be"cleaned up" (by the program) beforestoring it in memory (in parallel arrays) using the "direct address storage algorithm". 2nd) The user is then presented with a menu of query options, which the program then answers for them. (The user will be able to repeatedly enter queries until "DONE" indicated).

INPUT DATA FILE: CountriesData2000.csv(Data from 2000). The 1st record is a "header record" containing the field-identifiers - skip over this record. The remaining records each contain the following fields in this order:
code - a 3-letter unique identifier for the country
id - a small integer which uniquely identifies the country
(1 through N, although the data is NOT sorted on id)
name - a variable-length string - names are unique within the data set
continent - 1 of these 7: Africa, Antarctica, Asia, Europe, North America, Oceania, South America
region - a sub-region within the continent
size - land size in square kilometers - an integer (the largest is 8-digits, so an int will suffice)
population - an integer (largest is a 10-digit number, but only 1,277,558,000, so an int will suffice)
lifeExp - lifeExpectancy - a floating point number with 1 decimal place (an integer for .0 data)
governmentType - not used in this project
shortCode - not used in this project

CLEANING THE INPUT DATA: The data from the file needs "cleaning" before it is stored in the arrays. These are the issues that need to be fixed:
- Remove this from the front of each record: INSERT INTO 'Country' VALUES (
- Remove this from the end of each record: );
- Remove the surrounding single quotes from the non-numeric fields
- NOTE: the replace method can be used for these

USER INPUT: User enters their choice (2 characters) after being shown the menu of options.

OUTPUT TO USER #1: Menu presented to user (a DialogBox)
Choose one of the following:
MP: Median population
MS: Median land size
ML: Median life expectancy
SN: Show country (by name)
SI: Show country (by id)
SC: Show country (by code)
CO: Show all countries in continent
DO: DONE
NOTE: User can enter cap or small letters (program uses toUpperCase method).

OUTPUT TO USER #2: The answer to the user's query (displays in Console Window). HOWEVER, the data must be clearly labeled so the user sees what his/her QUERY was (because the query was entered in a DialogBox, which disappeared by now, and not the Console Window).

STORAGE: 7 parallel arrays for: code, name, continent, region, size, population, lifeExp
IMPORTANT NOTES:
1. Because "direct address storage algorithm" is used [SEE BELOW] to decide on the storage location (i.e., the index) based on the id field, it is not necessary to actually STORE the id field.
2. Country id's are between 1 and N, inclusive. No country has id 0. So NO data is stored in location [0], even though there IS a location [0] in all the 7 arrays. So any processing of the arrays uses 1 to <= n for it's looping, and NOT 0 to< n.
3. If some method ever needs to sort the data, do NOT DAMAGE this main data storage - i.e., the 7 arrays of clean data. Instead, (e.g., for ind median), the method would make a COPY of the array and sort THAT array.
4. Since program does NOT know how many input data records there will be ahead of time, the array sizes should all be "plenty big" (of size MAX_N = 300). HOWEVER, when reading in the data, keep track of n, and use n (and not array's length) to do any processing.
5. The initial header record is NOT included in n - only the real data records.

METHODS IN Utility CLASS(in a separate .java file from main's class)
- cleanData - raw data line sent in, cleaned up data line returned
- getUserOption - menu displayed (dialog box) and user-specified option returned (capitalized, in case user entered small letter)
- findCountryIndex - does a linear search of name array to find target, and returns index where it was found OR a -1 if NOT FOUND
- findCodeIndex - does a linear search of name array to find target, and returns index where it was found OR a -1 if NOT FOUND
- getContinent - displays list of 7 continents (Africa, Antarctica, Asia, Europe, North America, Oceania, South America) with 1-7 next to them (dialog box) - user enters1-7 for their choice - that choice is converted into the continent NAME (as a String) and that's returned to caller (i.e., Africa, Europe, . . .).
- showNameArray - displays a partial list of the name array including name and the index. Only print 1-20, then a space, then 101-120, then a space, then 220-n (the last country) - this method is called just after the data is loaded from the file into memory

METHODS IN QueryHandler CLASS(in a separate .java file from main's class)
- showMedianPop - population data sent in, a COPY of array is made and sorted, then median value printed.
- showMedianSize - same idea as above - but convert land size from square kilometers to square miles to print
- showMedianLifeExp - same idea as above
- showCountryById- print data (the 8 fields) for the country in location [id]
- showCountryByName - ask user for country name (DialogBox), call findCountryIndex to get its index, and print the data (the 8 fields, including id) for the country at that index location
- showCountryByCode - ask user for country code (DialogBox), call findCodeIndex to get its index, and print the data (the 8 fields, including id) for the country at that index location
- showContinent - calls getContinent to determine user's desired continent. Searches data to find ALL matching countries in that target continent and prints the country codes, their names and their regions.

DIRECT ADDRESS STORAGE ALGORITHM: This means that a country with id 25 would have its data stored in spot [25] in each of the 7 arrays. A country with id 200 would have its data stored in spot [200] in all 7 arrays.

MEDIAN: The value where half the values > this one, and half are

COPYING/SORTING ARRAYS: Only copy the N records (from 1 to N) into the NEW array for sorting. Do NOT use the entire MAX_N (or array.length) to control copying, as most of that array is empty (or "garbage").

PRINTING A COUNTRY - use this format for the 8 fields
NOTE: Truncate any country name or region which is longer than 15 characters to make it only 15 char's)
229 (USA)-United States - in North America (North America region)
Population: 278,357,000Land size: 9,363,520 sq.km. Life expectancy: 77.1

Java, Programming

  • Category:- Java
  • Reference No.:- M92397553
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As