March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Random NumbersRandom Numbers Output filesOutput files Input filesInput.

Slides:



Advertisements
Similar presentations
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Tomorrow’s ExamTomorrow’s Exam Today’s LabToday’s Lab SortingSorting.
Advertisements

March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Three exam questionsThree exam questions Lab with filesLab with.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reading numbers from dialogsReading numbers from dialogs Converting.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class AdministrativeAdministrative –Project proposals –This week’s lab Notes.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Designing Graphical ObjectsDesigning Graphical Objects The ‘divide.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Lab 16Lab 16 Filling in an arrayFilling in an array Searching for a.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class More about FunctionsMore about Functions RecursionRecursion.
March R. Smith - University of St Thomas - Minnesota Today’s Class Recap of a simple programRecap of a simple program A “history” of CA “history”
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class IF StatementIF Statement Revisiting assignment statementsRevisiting.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Hard Drives – more laterHard Drives – more later MethodsMethods.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam TopicsExam Topics.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class The project assignment, againThe project assignment, again Arrays.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Functions and Array ArgumentsFunctions and Array Arguments ExamExam.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Today: covering through P. 83 of textToday: covering through P. 83 of.
March R. Smith - University of St Thomas - Minnesota Today’s Class Course StuffCourse Stuff –Classroom change TOMORROW –Assignment; Lab While LoopsWhile.
March R. Smith - University of St Thomas - Minnesota Today’s Class Program LayoutProgram Layout Problem SolvingProblem Solving Reading InputReading.
March R. Smith - University of St Thomas - Minnesota Today’s Class RecapRecap More course thingsMore course things Work on labs/projectsWork on labs/projects.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Final Exam ReviewFinal Exam Review –Assessment –Exam Format –C –Matlab.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam StatusExam Status Recap of Lab 7 ExampleRecap of Lab 7 Example.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class I/O ObjectsI/O Objects Lab 12Lab 12.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Young Scholars GrantsYoung Scholars Grants Exam Next TuesdayExam Next.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Today’s LabToday’s Lab SortingSorting.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reviewing previous workReviewing previous work Using a dialog boxUsing.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class End of Chapter 2: READ Section 2.15End of Chapter 2: READ Section.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class HomeworkHomework Nested LoopsNested Loops Other thingsOther things.
March R. Smith - University of St Thomas - Minnesota CISC Class Today Return Homework; grading recapReturn Homework; grading recap “Enigma”
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Class projectsClass projects Lab 13: Use the method documentation.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230 – Today in Class Getting Homework BackGetting Homework Back DecimalFormat class.
6/22/2015 1R. Smith - University of St Thomas - Minnesota QMCS Class Today St. Lukes Case StudySt. Lukes Case Study.
March R. Smith - University of St Thomas - Minnesota QMCS Class Today Working the InternetWorking the Internet RoutingRouting Firewalling in.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Return HomeworkReturn Homework Class ScheduleClass Schedule Functions:
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Exam ReviewExam Review Arithmetic - I think everyone gets thisArithmetic.
March R. Smith - University of St Thomas - Minnesota QMCS Class Today Cryptography – introductory termsCryptography – introductory terms “Enigma”
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class MethodsMethods Problem solving by decompositionProblem solving by.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230 – Today in Class Authorizing OvertimeAuthorizing Overtime Weird Java stuff: conditionals,
March R. Smith - University of St Thomas - Minnesota Today’s Class Lab 1 commentsLab 1 comments Data Types in Chapter 4Data Types in Chapter 4 Lab.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Nested IFNested IF “Boolean” Logical Operations“Boolean” Logical.
March R. Smith - University of St Thomas - Minnesota ENGR 330: Today’s Class More “Clarifications” ?More “Clarifications” ? Interrupts – integrating.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Lab Status, Paper StatusLab Status, Paper Status Comments on Ints vs.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Data IndependenceData Independence Matlab #3: Exercise 5.1Matlab #3:
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Buttons: Radio and Check BoxButtons: Radio and Check Box Lab 20Lab.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class StatusStatus –Survey –Returning homework ArraysArrays –What are they?
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Finish up Lab 13Finish up Lab 13 Lab 14 – DetailsLab 14 – Details.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class The examThe exam –Open book, no notes, like last time Exam TopicsExam.
March R. Smith - University of St Thomas - Minnesota ENGR 330: Today’s Class Administrative: do you want another lab?Administrative: do you want.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Revised Lab 14/15Revised Lab 14/15 Counting WordsCounting Words Moving.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class About HomeworkAbout Homework Increment/DecrementIncrement/Decrement.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Homework & GradesHomework & Grades Multiple DimensionsMultiple Dimensions.
March R. Smith - University of St Thomas - Minnesota Today’s Class Homework NotesHomework Notes –Always try to match the printed output if I give.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Change in order of topicsChange in order of topics –Starting Chapter.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class More LoopsMore Loops Do While – a ‘trailing decision’ loopDo While.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Nested For loopsNested For loops IF StatementsIF Statements Else StatementElse.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class The ExamThe Exam Homework NotesHomework Notes.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Peek at Lab 16Peek at Lab 16 Side effects and arraysSide effects and.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class AssignmentsAssignments Logical operationsLogical operations Summations.
9/21/2015 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class RecapRecap Files, writing filesFiles, writing files 1D Array Recap1D.
5/27/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class RecapRecap Drawing in 2 dimensionsDrawing in 2 dimensions Vertical HistogramVertical.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Grades & Lab 12Grades & Lab 12 Upcoming ExamUpcoming Exam StructuresStructures.
The Concept Jam Health edition This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 2.5 Canada License. To view a copy.
March R. Smith - University of St Thomas - Minnesota QMCS Class Today “Enigma” recap and finish“Enigma” recap and finish The quiz/surveyThe.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class A note on methodsA note on methods ObjectsObjects Creating your.
1/28/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Assignments 7 and 8Assignments 7 and 8 ExamExam History Paper AssignmentHistory.
Files Review For output to a file: –FileOutputStream variable initialized to filename (String) and append/not append (boolean) –PrintWriter variable initialized.
2/22/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class History Paper scheduleHistory Paper schedule RecapRecap Plus PlusPlus.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class What’s on the Exam Next Week?What’s on the Exam Next Week? Lab 8Lab.
7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Collect PapersCollect Papers Review: Our ZeroesReview: Our Zeroes Review:
7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Computer HardwareComputer Hardware Recap: next programRecap: next program.
Introduction to programming in java
Reading from a file and Writing to a file
Reading from a file A file is typically stored on your computers hard drive. In the simplest case, lets just assume it is text. For a program to use.
Presentation transcript:

March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Random NumbersRandom Numbers Output filesOutput files Input filesInput files Informal Lab 9Informal Lab 9

March /18R. Smith - University of St Thomas - Minnesota Random Numbers The Random class (not this one)The Random class (not this one) –import java.util.Random; –… –Random rand = new Random(); –System.out.println(“Random double: “+rand.nextDouble()); –System.out.println(“Random int : “+rand.nextInt()); –System.out.println(“Random small int : “+rand.nextInt(25));

March /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

March /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

March /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);

March /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 File fn; // identify the file to readFile fn; // 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);

March /18R. Smith - University of St Thomas - Minnesota Program to assign numbers Collect the file nameCollect the file name Open the file/create File objectOpen the file/create File object –If not exists, write error messag. –ELSE Set up the scannerSet up the scanner Loop while “hasNext()Loop while “hasNext() –Read student name from file –Get random ID number –Println ID number and student name End loopEnd loop Done!Done!

March /18R. Smith - University of St Thomas - Minnesota Some Examples Read student names, substitute in text.Read student names, substitute in text. –Use hasNext() method to check for end of file Collect the name of the file from the userCollect the name of the file from the user –Use exists() method to check for a ‘real’ file Mini-Lab 9:Mini-Lab 9: Calculate the average of some numbers in a fileCalculate the average of some numbers in a file –Use hasNext() and exists()

March /18R. Smith - University of St Thomas - Minnesota That’s it. Questions?Questions? 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 or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.