DOC PREVIEW
TRINITY CSCI 1311 - Spreadsheet Processing
Pages 11

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Files/Spreadsheet Processing3/2/2009Opening Discussion●Midterm results. Will be returned on Wednesday. Log into grading program using your normal login name with your 7-digit ID number as the password.●Grades are subject to change. There could be a curve after extra credit problems are turned in.Objectives●We have a new topic and new goals. We are going to see how programming can let you do things with tabular data that you might have problems doing with standard programs.●First, we need to learn how to read information from a file and put it into our program.●After that we will work on processing the data.Spreadsheet Scenario●We have a new scenario that we are going to work with called spreadsheet.●This scenario has a world that shows a grid.●The grid can be filled with numbers that are drawn on the world.●What we want to do today is fill in the readFile() method so that it can read in CSV text files.Numbers with Decimals●The numbers we are dealing with might have decimals.●For that reason, we can't use the int type.●Instead we will use the double type. Double stands for double-precision floating point. These aren't real numbers in the mathematical sense, they have limited precision.●Our table uses the Double class which is a wrapper for double so it return null.Reading from File●We are going to use the java.util.Scanner class for reading from files.●Let's look at the API entry for that.●To read from a file we will use the constructor that takes a java.io.File object.●Let's look at the API entry for File.●By default Greenfoot looks for files in the directory of the current scenario.Strategy●Here is what we want to do in readFile() to read a CSV file.●Make a scanner.●While the scanner has more lines–Read a line–Split the line on commas–For each of the values●Add it to the tableExceptions●When things go wrong in Java the code throws exceptions. Files can have lots of things go wrong.●Use a try block when you want to try to do something that might throw an exception then catch that exception.–try {●Statements–} catch(ExceptionType e) {●Statements–}The while Loop●Not everything we repeat in code is well modeled by counting. Reading all the lines in a file is an example.●The while loop allows you to repeat something as long as a condition is true.●while(condition) {–Statements●}The split Method●One way to break a string up into parts is with the split(String delim) method of the String class.●You pass it the delimiter to split on and it gives you back a String[].●We will use split on the line we read and then have a for loop go through the array.Minute Essay●What are your plans for spring break?●Remember that the TA will be in class on Wednesday and Friday. He will help with midterm extra credit or whatever else you want to talk


View Full Document

TRINITY CSCI 1311 - Spreadsheet Processing

Course: Csci 1311-
Pages: 11
Documents in this Course
Arrays

Arrays

12 pages

Arrays

Arrays

10 pages

Applets

Applets

5 pages

Arrays

Arrays

8 pages

Methods

Methods

12 pages

Drawing

Drawing

8 pages

Load more
Download Spreadsheet Processing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Spreadsheet Processing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Spreadsheet Processing 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?