Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

an element of formality in the workplace between different levels;

Answered: 1 week ago