Pgm5.Step1

Pgm5.Step1 - "Here is my first java attempt...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
make sure you can create a text file (I called it quiz.txt) and a main() routine that can access the file and read (and do nothing to it…) until end of file and close. Obviously, we will do more, but to be able to access and process the file without an ‘exception’ is the first step. My test file, quiz.txt contains the following entries: Who was the first US President?, George Washington, 1 Who was the second US President?, John Adams,1 Who was the third US President?,Thomas Jefferson, 1 Who was the fourth US President?, James Madison,1 Who was the sixteenth US President?, Abraham Lincoln,1 What follows is my java driver program… import java.io.*; import java.util.*; public class MasterQuiz { /** * The MasterQuiz Problem * Familiarizes students with: file I/0: StringTokenizer; Multiple classes; * _serious UML design; ArrayList (dynamic storage alloocation); Exceptions, *__and more. .. * @author Bob Roggio */ public static void main(String [] args) throws FileNotFoundException {_ System.out.println (
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: "Here is my first java attempt using JGrasp" ); FileReader theFile = new FileReader ( "quiz.txt" ); BufferedReader fileHandle = new BufferedReader (theFile); String CurrentLine; String Currenttoken; System.out.println( "Statistics for file :" + "quiz.txt" ); try { while ( ( CurrentLine = fileHandle.readLine() ) != null ) System.out.println(CurrentLine); fileHandle.close(); } // end try catch (Exception e) { System.out.println(e); } } // end main() }// end MasterQuiz Output appears as: ----jGRASP exec: java MasterQuiz Here is my first java attempt using JGrasp Who was the first US President?, George Washington, 1 Who was the second US President?, John Adams,1 Who was the third US President?,Thomas Jefferson, 1 Who was the fourth US President?, James Madison,1 Who was the sixteenth US President?, Abraham Lincoln,1 ----jGRASP: operation complete....
View Full Document

Page1 / 2

Pgm5.Step1 - "Here is my first java attempt...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online