To Documents

IT 313 -- Project 5

JFreeChart Graphs

These examples are relevant:
WriteGreetings (input-output)  ReadFromWeb (input-output)  BarGraph (jfreechart)  PersonCol (PersonCol)

Details:

  1. 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.
  2. Before you try to obtain currency exchange rates, obtain your free 32 character access code from this website:
    https://fixer.io/
    
    Click the GET FREE API KEY button on the top right.
  3. 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. Search online for these abbreviations with a search string such as "ISO 4217 Currency Codes." Place these currency codes in a text file named currency.txt.
  4. The following URL is a link to a CSV file that contains the exchange rate for a given source and target currency. For example, if the source currency is EUR and the target currency is USD, the URL is
    http://data.fixer.io/api/latest?access_key=
         <<Your access key goes here>>&symbols=GBP
    
    The returned JSON string is
    {"success":true,"timestamp":1538281746,"base":"EUR",
     "date":"2018-09-30","rates":{"GBP":0.891903}}
    
  5. To obtain all of the available currencies returned by this website, omit the symbols argument:
    http://data.fixer.io/api/latest?access_key=
         <<Your access key goes here>>
    
  6. Use try..catch blocks to handle all exceptions with a user-friendly messages in the catch blocks. Do not throw any exceptions.
  7. 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).
    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.
    Identify the source code items that belong before, in, and after the while loop.
  8. Don't forget to close each scanner when you are finished using it.
  9. 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 IntelliJ Refactor capability to extract the methods.
  10. 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 IntelliJ 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
    
  11. Grading Breakdown:   Functionality: 70%; Comments: 10%; Indentation: 10%; Submitted Correctly: 10%