Question: NEED HELP WITH JAVA void loadFile() { File file = new File(currency.txt); try { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), UTF8)); String line =

NEED HELP WITH JAVA

NEED HELP WITH JAVA void loadFile() { File file = new File("currency.txt");

void loadFile() {

File file = new File("currency.txt"); try { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8")); String line = in.readLine(); while ( line != null ) { // Process 'line' (split up). String [] parts = line.split(","); // validate, store somewhere etc. line = in.readLine(); // read next line (if available) } in.close(); } catch (Exception e) { // Something went wrong. String msg = e.getMessage(); // show the message to the user! }

}

For this requirement the program should be improved so that it no longer relies on hard coded conversion values for the various currencies. In reality the conversion rates constantly change. In order to better support this the available currencies, conversion factors, and currency symbol should be stored in a text file. When the application first starts the contents of this text file (called currency.txt) should be accessed and imported into the program, thus changing the list of supported currencies and the current conversion rates. You will be provided with sample files to use during the development. Typical file content is shown below. Your program should assume the file is always in this format. Euro (EUR), 1.06, South African Rand (ZAR), 17.96, R New Zealand Dollar (NZD), 1.8, NZ$ Note: the file will be UTF-8 encoded (to handle the special non-ASCII characters), so to read the file use something like - BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8")); In some cases, the file contents may be corrupt, so your program must be able to identify invalid entries and discard them. Any invalid entries found should be reported via a dialogue box when the application accesses the file contents. For example, a file with invalid entries may look like the following. Canadian Dollars (CAD), 4a, c$ United Arab Emirates Dirham (AED) 4.2, 1.- , 45.2: % Thai Baht (THB), 44.1, B In the above example the first three entries are invalid, but the final one is correct. Hence only the final currency information should be made available by the program. The other three should be reported as invalid when the program first starts

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!