To Lecture Notes

IT 313 -- Feb 6, 2020

Review Exercises

  1. How do you cause a Java program to terminate immediately?
  2. What is a JAR file? How do you add a JAR file to your project?
  3. In the BarChart class of the JFreeChart Example, remove the two JAR files from the project, then add them back in.
  4. What does inheritance do for you? Check how inheritance is used in the Drawing Example.
  5. What is the is-a test?
  6. What is the difference between static methods and instance methods?
  7. What is the difference between method overloading and method overriding?
  8. Look at the shapes module in the Inheritance Example.
    Look at the Random Circles frame.

Project 4

JAR Files

Project 5

  1. Look at the Project 5 Description.
  2. main method that obtains the currency exchange rate for U.S. Dollars (USD) from the io.fixer website.
    Note: the source currency or base currency is Euro  (EUR).
    Obtain your free access key and insert it into the URL before running this code.
    public static void main(String[ ] args) 
        throws IOException, MalformedURLException {
    
        String prefix = "http://data.fixer.io/api/latest";
        String accessKey = "?access_key=<<Insert your access key here>>";
        String insert = "&symbols=";
        String targetCurrency = "USD";
        String urlString = prefix + accessKey + insert + targetCurrency; 
        System.out.println(urlString);
    
        URL url = new URL(urlString);
        Scanner s = new Scanner(url.openStream( ));
        String jsonString = s.nextLine( );
        System.out.println(jsonString);
        int start = jsonString.indexOf(targetCurrency) + 5;
        int end = jsonString.length( ) - 2;
        System.out.println("start: " + start + " end: " + end);
        System.out.println(jsonString.substring(start, end));
        s.close( );
    }
    

Additional Examples