Assignment 6 – Country Database with flags

Maximum Points = 50

The purpose of this lab is to continue your introduction to user-defined classes and to the Scanner, File, and Frame classes in the Java programming language. In this assignment, you will write a program that reads data from thee files and then display country information and the flags of the user-selected countries.

v  Your program will ask the user to pick a continent(Asia, Africa, or Europe) and then your program will read the data from one of the three files called asia.csv, europe.csv, and africa.csv

o  HINT: You will need to use the Scanner class described on page A41 and example with a File class described on page A18 and pp. 514-516 (examples in CougarView’s Instructor Links and Files in the Scanner and URL Dissector folders in the Solutions folder.)

o  NOTE: you will need to use a delimiter as illustrated in the examples to separate the data components.]

v  The data in each file will consist of five (5) countries (each country will consist of a country code, country name, population, area, GDP, Literacy Rate) where the data is comma-separated (e.g. AZ,Azerbaijan, 7961619,86600,3400,97)) where each component will be separated by a comma. Associated with each data file are five images files representing the flags of the five countries. Each file is named with the country code (e.g. Azerbaijan’s flag is in the file az.gif)

v  Your program must include a class that will hold the Country data (complete with constructor(s), get and set methods for each instance variable, and a toString method that returns the contents of the instance variables). Include an additional method getFlag (returns the flag of the country as a BufferedImage.) using code similar to

public BufferedImage getFlag() throws IOException

{

File imgFile = new File(flagFilename);

BufferedImage img = ImageIO.read(imgFile);

return img;

}

v  Once your program has collected the data, you need to display the listing of the five countries including the flag on the same screen using a JFrame and code similar to

try

{

BufferedImage img = getPic();

g2.drawImage(img,0,0, this );

}

catch (IOException exception)

{

JOptionPane.showMessageDialog(null, "file not opened");

}

v  Your listing should have a title at the top in a larger font (and different font face and color).. The listing of the five countries should display the data from the file with headings, PLUS the flag.

Modularize your program to minimize the amount of changes you would need to make if we change the number of countries.

EXTRA CHALLENGES:

·  Ask the user for the file name (from System.in or with a JFileChooser).

·  Display information for a user-selected country

Make sure that your program uses proper indentation and complete documentation. See http://csc.columbusstate.edu/summers/NOTES/1301/style.htm for guidelines.

The program heading should occur at the top of the program and should include:

/**

* PROGRAM SPECIFICATIONS

* NARRATIVE DESCRIPTION:

*

* @author (your name)

* @version (date)

*/

(Due before 8 a.m. on Wednesday, October 23, 2013) Submit a .doc file containing the UML class diagrams (including the “main” class) showing inheritance for all the classes used in your program and your timesheet documenting your time so far to the dropbox in CougarView. [10 pts]

(Due before 8 a.m. on Wednesday, October 30, 2013) Submit your .java files containing your program and your timesheet documenting your time to the dropbox in Cougarview.

Grades are determined using the following scale:

 Header..………………….:___/2
 Data members……..……:___/4
 Methods..………………..:___/4 / ·  Runs correctly..…………………:___/10
·  Correct output……..……………:___/10
·  Design of output..………………:___/8
·  Design of logic…………………:___/10
·  Standards……………………….:___/7
·  Documentation.………………...:___/5