
Spring 2023 CSE Lesson 15 with Miya Natsuhara and Spring Vibes
"Stay updated with announcements for quiz retakes and project deadlines in CSE Lesson 15 for Spring 2023 with Miya Natsuhara. Learn about file I/O, scanners, and processing patterns. Don't miss out on the final exam details!"
Uploaded on | 0 Views
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
CSE 121 Lesson 15 Miya Natsuhara Spring 2023 Music: 121 23sp Lecture Vibes TAs: Jasmine Shananda Vidhi Larry Jacqueline Afifah Atharva Julia Anju Lydia Jonus Hugh Mia Archit Grace Kailye Joshua James Justin Aishah Claire Lydia Kai sli.do #cse121
Announcements, Reminders Form for Quiz Retakes on May 23 released later today Quiz 1 and Quiz 2 will be eligible for retake (last opportunity for Quiz 1) Quiz 2 grades posted later today Creative Project 2 was released on Wednesday File I/O and last time with Turtles Due Tuesday May 23 Reminder: Final exam Thursday, June 8 2:30pm-4:20pm Lesson 15 - Spring 2023 2
(PCM) Scanner & File for File I/O File newFile = new File("newFile.txt"); Scanner fileScan = new Scanner(newFile); File is defined in the java.io package import java.io.*; Scanner Methods Description Reads the next token from the user as an int and returns it nextInt() Reads the next token from the user as a double and returns it nextDouble() Reads the next token from the user as a String and returns it next() Reads an entire line from the user as a String and returns it nextLine() Returns true if the next token can be read as an int, false otherwise hasNextInt() Returns true if the next token can be read as a double, false otherwise hasNextDouble() Returns true if there is another token of input to be read in, false otherwise hasNext() Returns true if there is another line of input to be read in, false otherwise hasNextLine() Lesson 15 - Spring 2023 3
(PCM) Typical Line-Processing Pattern while (fileScan.hasNextLine()) { String line = fileScan.nextLine(); // do something with line } Lesson 15 - Spring 2023 4
(PCM) Typical Token-Processing Pattern while (fileScan.hasNext__()) { __ nextToken = fileScan.next__(); // do something line nextToken } Lesson 15 - Spring 2023 5
(PCM) Typical Hybrid Pattern while (fileScan.hasNextLine()) { String line = fileScan.nextLine(); Scanner lineScan = new Scanner(line); while (lineScan.hasNext__()) { __ nextToken = lineScan.next__(); // do something with nextToken } } Lesson 15 - Spring 2023 6
(PCM) Scanning Numeric Data On Wednesday, we primarily used String-based Scanner methods to read input from a file. Let's work with some numeric data now! We're going to make more use of hasNextInt() hasNextDouble() nextInt() nextDouble() Assumptions about our file's format! Lesson 15 - Spring 2023 7
Poll in with your answer! What would be the result of running the FindMinAndMax program with this as input? A.Error B.minimum was -1.0005 and maximum was 17.0 C.minimum was 0.73 and maximum was 17 D.minimum was 0.73 and maximum was 17.0 Lesson 15 - Spring 2023 8
Poll in with your answer! What would be the result of running the FindMinAndMax program with this as input? A.Error B.minimum was 0.0 and maximum was 17.0 C.minimum was 0.73 and maximum was 17.0 D.minimum was 0.73 and maximum was 17 Lesson 15 - Spring 2023 9
(PCM) PrintStream File outputFile = new File("out.txt"); PrintStream output = new PrintStream(outputFile); PrintStream is defined in the java.io package import java.io.*; Description Scanner Methods Prints the given value to the set output location. print( ) Prints the given value to the set output location, and then terminates the line. println( ) Lesson 15 - Spring 2023 10