Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write this in Java, please write comments as you create it, and please follow the coding instructions. As you are working on this project,

  • Please write this in Java, please write comments as you create it, and please follow the coding instructions.
  • As you are working on this project, add print statements or use the debugger to help you verify what is happening. Write and test the project one line at a time.
  • Before you try to obtain currency exchange rates, obtain your free 32 character access code from this website:
    https://fixer.io/ Here's the code: 46f27e9668fcdde486f016eee24c554c
  • Choose five international source currencies to monitor. Each currency is referenced with a three letter ISO 4217 currency code. For example, the code for the British Pounds is GBP. " Place these currency codes in a text file named currency.txt.
  • Use these codes: Colombian Peso: COP: 3540 .250862, Costa Rican Colon CRC: 685.938731, Egyptian Pound EGP: 19.758935, Jamaican Dollar JMD: 150.549578, and Yen JPY: 124.536082 place them in a file called currency.text
  • Use try..catch blocks to handle all exceptions with a user-friendly messages in the catch blocks. Do not throw any exceptions.
  • In a while loop that terminates when the end of file is reached, do the following:
    1. Read the next currency from the currencies.txt file.
    2. Create a URL for the fixer.io site that will obtain a URL for obtaining the exchange rate using the currency read in Step 1 as the target currency (symbol) and EUR as the source currency (base). Which you code:
      http://data.fixer.io/api/latest
      ? access_key = 46f27e9668fcdde486f016eee24c554c or YOUR_ACCESS_KEY instead of the code itself, one of them should work
       & symbols = COP,CRC,EGP,JMD,JPY
    3. Using the URL from Step 2, create a scanner object that reads the JSON string from the website. Extract the exchange rate from the JSON string.
    4. Add a bar to a JFreeChart bar chart, whose height is the exchange rate from Step 3. This is the bar chart example:
      // JAR files jcommon-1.0.23.jar and jfreechart-1.0.19.jar // must be added to project. import java.io.*; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.chart.ChartFactory; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.JFreeChart; import org.jfree.chart.ChartUtilities; public class BarChart { public static void main(String[] args) { try { // Define data for line chart. DefaultCategoryDataset barChartDataset = new DefaultCategoryDataset(); barChartDataset.addValue(1435, "total", "East"); barChartDataset.addValue(978, "total", "North"); barChartDataset.addValue(775, "total", "South"); barChartDataset.addValue(1659, "total", "West"); // Define JFreeChart object that creates line chart. JFreeChart barChartObject = ChartFactory.createBarChart( "Sales ($1000)", "Region", "Sales", barChartDataset, PlotOrientation.VERTICAL, false, // Include legend. false, // Include tooltips. false); // Include URLs. // Write line chart to a file. int imageWidth = 640; int imageHeight = 480; File barChart = new File("sales.png"); ChartUtilities.saveChartAsPNG( barChart, barChartObject, imageWidth, imageHeight); } catch (Exception i) { System.out.println(i); } } }
    Identify the source code items that belong before, in, and after the while loop.
  • Don't forget to close each scanner when you are finished using it.
  • Your project should contain only a single class, which contains the main method. This class must define at least three additional static methods that modularize the tasks in this project. For example, you might define methods such as these:
    public static String getCurrency(Scanner s) public static String getUrlString(String targetCurrency) public static double getExchangeRate(String urlString) 
    If you wish, use the Eclipse Refactor capability to extract the methods.
  • Here is suggested pseudocode for the whole project. You can get this to work first and then extract the methods, either by hand or using Eclipse Refactor:
    create File object for currencies.txt create scanner1 to read from input file create new DefaultCategoryDataset object to contain bars for histogram while more lines in input file read target currency using scanner1 construct URL for obtaining target exchange rate create scanner2 from URL use URL to obtain JSON string extract target exchange rate from JSON string add histogram bar representing target exchange rate to DefaultCategoryDataset object close scanner2 end while create a bar chart object from DefaultCategoryDataset object create graphics image file close scanner1

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

More Books

Students also viewed these Databases questions

Question

=+What is the big message you want them to know?

Answered: 1 week ago

Question

=+What do they (audience members) currently think?

Answered: 1 week ago