QMCS 230: Today in Class - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

QMCS 230: Today in Class

Description:

Less credit than the 'formal' lab. Checked in general for content and form. 1 ' ... public static void main(String[] args) throws IOException. PrintWriter pwa; ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 16
Provided by: ricks6
Category:

less

Transcript and Presenter's Notes

Title: QMCS 230: Today in Class


1
QMCS 230 Today in Class
  • Homework
  • Nested Loops
  • Other things
  • Group work if time
  • Start working with files?
  • Lab 8

2
Homework
  • Typical weekly assignments
  • 1 informal lab
  • Hand in source code ONLY
  • Less credit than the formal lab
  • Checked in general for content and form
  • 1 formal lab
  • E-mail source code ONLY
  • Checked carefully
  • Grading
  • 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
On the Exam
  • Chapter 2, all sections except
  • 2.6, 2.8
  • Chapter 3, all sections except
  • 3.8, 3.9
  • Chapter 4, Sections 4.1-4.6
  • Study the Checkpoints

4
Reference Materials
  • I will provide reference guides
  • Java syntax basics
  • Reserved words you might use
  • Tables of details, if needed
  • Closed book closed notes

5
Nested Loops
  • How would we do hhmmss ?
  • What does nesting mean?
  • Nothing to do with eggs.

6
Break and Continue (Sec 4.8)
  • Loops do all statements in order
  • Break and Continue change this.
  • Cause surprising behavior
  • They exist, but we will NOT use them
  • Makes programs harder to understand
  • And harder for ME to read

7
Picking a loop
  • Always do it at least once?
  • Maybe skip it all sometimes?
  • A fixed number of times?

8
Picking a loop
  • Always do it at least once?
  • Do - While
  • Maybe skip it all sometimes?
  • While
  • A fixed number of times?
  • For loop

9
Group Work
  • 8 groups - 4 problems
  • ALL average 4 numbers read from keyboard
  • Different problems
  • Use 4 separate statements
  • Use for loop
  • Use do while loop
  • Use while loop

10
Working with Files
  • We use the same methods as System.in/out
  • println, print, printf, Scanner class
  • We must open and close files
  • Open when we create the file object
  • close() method when done

11
Output Files
  • PrintWriter class
  • new takes file name as an argument
  • Creates that file
  • Use the object with print methods
  • Write to a file
  • import java.io.
  • public static void main(String args) throws
    IOException
  • PrintWriter pwa
  • pwa new PrintWriter(existingfile.txt)
  • Example write student names

12
Append to Output File
  • Use an extra object for the existing file
  • FileWriter object
  • FileWriter fw // to define the existing file
  • PrintWriter pwa // to open for print functions
  • fw new FileWriter(existingfile.txt, true)
  • pwa new PrintWriter(fw)

13
Input Files
  • Use Scanner class and File class
  • import java.util.Scanner
  • import java.io.
  • public static void main(String args) throws
    IOException
  • fn // identify the file to read
  • Scanner sc // for reading the data
  • fn new File(filename.txt)
  • sc new Scanner(fn)

14
Thats it.
  • Questions?

15
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.
Write a Comment
User Comments (0)
About PowerShow.com