Answered step by step
Verified Expert Solution
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
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 startsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started