DAT - Putting it All Together (Lesson)

APCompSci_LessonTopBanner.png

Putting it All Together

Introduction

Existing code in the form of libraries is incredibly useful and a powerful aspect of object-oriented programming. Beyond the standard Java library, users around the world have created and published libraries to perform countless tasks. One such library, which you will be using in this activity and the one that follows, is the Sinbad library. This library allows you to create a Java program that can connect to a data source, read in data, and then process this data.

The goal of this activity is to provide practice working with the Sinbad library. Before beginning, ensure that you have set up Dr. Java appropriately by following the Setup instructions in the previous lesson.

Record the answers to the following questions on a sheet of paper. You will need the answers to complete the Lab Check Quiz.

1. Run the main method in the Welcome01 class and provide the location and temperature that are printed. (The Welcome01 class is provided in the DataLabCode folder. If this file does not compile and run, go back and follow the Setup instructions in the previous lesson.)

2. Go to the following link, https://w1.weather.gov/xml/current_obs/ Links to an external site., and find the four-character code for an additional location. To find the code, you first must select the state or territory from the drop-down box shown here.

XML Weather condition 

From the resulting list, choose a four-character code and modify the main method in Welcome01 to pull information from this location instead. Provide the four-character code then write what is displayed when running your main method with this new code.

Once you have verified that the Sinbad library is installed correctly, work through the “Fetching Objects” tutorial found at https://github.com/berry-cs/sinbad/blob/master/tutorials/java/welcome02-obj.md Links to an external site.. Then answer the following question.

3. Using the location from the previous question, modify Welcome02_Object.java that you completed in the tutorial to create a third Observation object for your identified location, and then write the code to determine the coldest location between all three Observation objects. (Note: This file contains code for the Observation class so be sure that the Observation class file you created earlier has been closed in Dr. Java.)

Next you will work through the “Arrays and Lists of Objects” tutorial found at https://github.com/berry-cs/sinbad/blob/master/tutorials/java/welcome03-objs.md Links to an external site.. You can choose to either complete the Array or ArrayList portion of the tutorial. Then answer the following questions.

4. How many weather station objects are in your state?

5. What is another way you could filter weather stations?

6. Modify WeatherStation.java and Welcome03_List to filter based on latitude, showing the weather station that is furthest south. Do not remove existing code that sorts weather stations based on state. What is the southernmost weather station you found?

This lab content is from the CollegeBoard.

Tips for Working with Data

In order to manage large amounts of data or complex relationships in data, it is helpful to group the data together in such a way using a single variable that refers to a location capable of storing multiple items, rather than a single item. If the variable name holds multiple items, more information (an index) is needed to know which specific value is being accessed.

The iterative statement can be used to access every element starting at the beginning and moving to the last element. It has a specific structure and can be used to take the place of repetitive code, reducing the amount of code written and the potential errors. When elements are inserted or deleted from an ArrayList, the loop counter needs to be adjusted in order to prevent skipping an element or trying to access elements that no longer exist.

In addition to parameters and local variables declared in a method, a method always has access to any instance variables that are declared within the closing class. These instance variables are often required to complete the goal of the method. If any of the available variables are objects (reference data), then those objects may have their own methods, variables, and constants that would be accessible within the given method as well.

Lab Check Questions

Record the answers to the following questions on a sheet of paper. You will need the answers to complete the Lab Check Quiz. (These questions are continued from the questions in the lesson.)

7. What is an additional question that can be answered about weather stations or observations based on the code that you wrote?

8. How much additional code would it take to answer this question?

APCompSci_LessonBottomBanner.pngIMAGES CREATED BY GAVS