Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class HomeworkHomework Nested LoopsNested Loops Other thingsOther things.

Similar presentations


Presentation on theme: "March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class HomeworkHomework Nested LoopsNested Loops Other thingsOther things."— Presentation transcript:

1 March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class HomeworkHomework Nested LoopsNested Loops Other thingsOther things Group work if timeGroup work if time Start working with files?Start working with files? Lab 8Lab 8

2 March 2005 2/18R. Smith - University of St Thomas - Minnesota Homework Typical weekly assignmentsTypical weekly assignments –1 “informal” lab Hand in source code ONLYHand in source code ONLY Less credit than the “formal” labLess credit than the “formal” lab Checked in general for content and formChecked in general for content and form –1 “formal” lab E-mail source code ONLYE-mail source code ONLY –Checked carefully GradingGrading –Check plus plus – a few labs – for special work – think A+ –Check plus – almost no problems – think A –Check – Some problems – think of a B –Check Minus – many or major problems – think of a C –No Credit – major parts of the assignment missing

3 March 2005 3/18R. Smith - University of St Thomas - Minnesota On the Exam Chapter 2, all sections exceptChapter 2, all sections except –2.6, 2.8 Chapter 3, all sections exceptChapter 3, all sections except –3.8, 3.9 Chapter 4, Sections 4.1-4.6Chapter 4, Sections 4.1-4.6 Study the ‘Checkpoints’Study the ‘Checkpoints’

4 March 2005 4/18R. Smith - University of St Thomas - Minnesota Reference Materials I will provide reference guidesI will provide reference guides –Java syntax basics –Reserved words you might use –Tables of details, if needed Closed book closed notesClosed book closed notes

5 March 2005 5/18R. Smith - University of St Thomas - Minnesota Nested Loops How would we do hh:mm:ss ?How would we do hh:mm:ss ? What does “nesting” mean?What does “nesting” mean? –Nothing to do with eggs.

6 March 2005 6/18R. Smith - University of St Thomas - Minnesota Break and Continue (Sec 4.8) Loops do all statements in orderLoops do all statements in order Break and Continue change this.Break and Continue change this. –Cause ‘surprising’ behavior They exist, but we will NOT use themThey exist, but we will NOT use them –Makes programs harder to understand –And harder for ME to read

7 March 2005 7/18R. Smith - University of St Thomas - Minnesota Picking a loop Always do it at least once?Always do it at least once? Maybe skip it all sometimes?Maybe skip it all sometimes? A fixed number of times?A fixed number of times?

8 March 2005 8/18R. Smith - University of St Thomas - Minnesota Picking a loop Always do it at least once?Always do it at least once? –Do - While Maybe skip it all sometimes?Maybe skip it all sometimes? –While A fixed number of times?A fixed number of times? –For loop

9 March 2005 9/18R. Smith - University of St Thomas - Minnesota Group Work 8 groups - 4 problems8 groups - 4 problems ALL: average 4 numbers read from keyboardALL: average 4 numbers read from keyboard Different problemsDifferent problems –Use 4 separate statements –Use ‘for’ loop –Use ‘do while’ loop –Use ‘while’ loop

10 March 2005 10/18R. Smith - University of St Thomas - Minnesota Working with Files We use the same methods as System.in/outWe use the same methods as System.in/out –println, print, printf, Scanner class We must “open” and “close” filesWe must “open” and “close” files –“Open” when we create the file object –“close()” method when done

11 March 2005 11/18R. Smith - University of St Thomas - Minnesota Output Files PrintWriter classPrintWriter class –“new” takes file name as an argument –Creates that file Use the object with ‘print’ methodsUse the object with ‘print’ methods Write to a fileWrite to a file –import java.io.*; –public static void main(String[] args) throws IOException –PrintWriter pwa; –pwa = new PrintWriter(“existingfile.txt”); Example: write student namesExample: write student names

12 March 2005 12/18R. Smith - University of St Thomas - Minnesota Append to Output File Use an extra object for the existing fileUse an extra object for the existing file “FileWriter” object“FileWriter” object FileWriter fw;// to define the existing fileFileWriter fw;// to define the existing file PrintWriter pwa;// to open for print functionsPrintWriter pwa;// to open for print functions fw = new FileWriter(“existingfile.txt”, true);fw = new FileWriter(“existingfile.txt”, true); pwa = new PrintWriter(fw);pwa = new PrintWriter(fw);

13 March 2005 13/18R. Smith - University of St Thomas - Minnesota Input Files Use Scanner class and File classUse Scanner class and File class import java.util.Scanner;import java.util.Scanner; import java.io.*;import java.io.*; public static void main(String[] args) throws IOExceptionpublic static void main(String[] args) throws IOException fn; // identify the file to readfn; // identify the file to read Scanner sc; // for reading the dataScanner sc; // for reading the data fn = new File(“filename.txt”);fn = new File(“filename.txt”); sc = new Scanner(fn);sc = new Scanner(fn);

14 March 2005 14/18R. Smith - University of St Thomas - Minnesota That’s it. Questions?Questions?

15 March 2005 15/18R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.


Download ppt "March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class HomeworkHomework Nested LoopsNested Loops Other thingsOther things."

Similar presentations


Ads by Google