20 Oct - Overview Homework #1 Group-Id rule Notes on Java text file input/output –Scanner class –Printf (like C)

Slides:



Advertisements
Similar presentations
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 3: Program Statements 3.6 – Iterators – p
Advertisements

JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
CS102--Object Oriented Programming
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Program development.
Text File I/O. Text Files and Binary Files Files that are designed to be read by human beings, and that can be read or written with an editor are called.
File I/O and Exceptions File I/O Exceptions Throwing Exceptions Try statement and catch / finally clauses Checked and unchecked exceptions Throws clause.
PACKAGES. PACKAGES IN JAVA A package is a collection of related classes and interfaces in Java Packages help in logical grouping of classes and interfaces.
Computer Science II Recursion Professor: Evan Korth New York University.
Introduction to Input and Output. Layers (or Tiers) of an Application  Software in the real world normally takes the form of a number of independent.
EXCEPTIONS Def: An exception is a run-time error. Examples include: attempting to divide by zero, or manipulate invalid data.
1 File Output. 2 So far… So far, all of our output has been to System.out  using print(), println(), or printf() All input has been from System.in 
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Structure of.
Files and Streams CS 21a Chapter 11 of Horstmann.
Chapter 8 Overview – Learn to use try catch blocks – Learn to use streams – Learn to use text files.
1 CSE 142 Lecture Notes File input using Scanner Suggested reading: , Suggested self-checks: Section 6.7 # 1-11, These lecture.
1 Fall 2008ACS-1903 for Loop Reading files String conversions Random class.
Slides prepared by Rose Williams, Binghamton University Chapter 10 File I/O.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 6: File Processing.
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
CS1101: Programming Methodology Aaron Tan.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA ‏ Packages.
Slide 1 of 19 Welcome to GSA’s Vendor and Customer Self Service (VCSS) course Section 7: Correspondence Navigation This presentation is compliant with.
Lesson 7: Improving the User Interface
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Chapter 10 Exceptions and File I/O. © 2004 Pearson Addison-Wesley. All rights reserved10-2 Exceptions Exception handling is an important aspect of object-oriented.
Guidelines for Homework 6. Getting Started Homework 6 requires that you complete Homework 5. –All of HW5 must run on the GridFarm. –HW6 may run elsewhere.
Moooooo Or: How I learned to stop worrying and love USACO.
Very Brief Introduction to Java I/O with Buffered Reader and Buffered Writer.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Lecture 2: Classes and Objects, using Scanner and String.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 11: Handling Errors; File Input/Output.
1 BUILDING JAVA PROGRAMS CHAPTER 6 FILE PROCESSING.
File Input/Output. 2Java Programming: From Problem Analysis to Program Design, 3e File Input/Output File: area in secondary storage used to hold information.
Java Chapter 9 File Input and Output. Objectives In this chapter you will: Learn how bits, characters, records, and files fit into a data hierarchy Explore.
CS100A, Fall 1997, Lecture 91 CS100A, Fall 1997 Lecture 9, Tuesday, 30 September Input/Output & Program Schema System.in, class Text, Some basic data processing,
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
Documentation Dr. Andrew Wallace PhD BEng(hons) EurIng
ECE 122 Feb. 1, Introduction to Eclipse Java Statements Declaration Assignment Method calls.
Using Oracle-Supplied Packages. 2 home back first prev next last What Will I Learn? Describe two common uses for the DBMS_OUTPUT server-supplied package.
CMSC 202 Text File I/O. Aug 8, Text Files and Binary Files Files that are designed to be read by human beings, and that can be read or written with.
Week 14 - Monday.  What did we talk about last time?  Inheritance.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
ITEC 320 Lecture 9 Nested records / Packages. Review Project ?’s Records Exam 1 next Friday.
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Georgia Institute of Technology Making Text for the Web part 2 Barb Ericson Georgia Institute of Technology March 2006.
Object and Classes อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 3.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
8 Nov 1.Backtracking 2.Structure clashes & program decomposition.
File I/O CLI: File Input CLI: File Output GUI: File Chooser
Streams & File Input/Output (I/O)
CMSC 202 Text File I/O.
Introduction to programming in java
Reading from a file and Writing to a file
Building Java Programs
Strings and File I/O.
Week 14 - Wednesday CS 121.
I/O Streams- Basics Byte Streams and Character Streams
File Input and Output TOPICS File Input Exception Handling File Output.
Fundamental Error Handling
File Handling in Java January 19
Chapter 8: Exceptions and I/O Streams
CS100A Lect. 10, 1 Oct Input/Output & Program Schema
Presentation transcript:

20 Oct - Overview Homework #1 Group-Id rule Notes on Java text file input/output –Scanner class –Printf (like C)

Homework #1 to JSE/Home Work/ due noon, Friday, 21 Oct solution as (zipped) attachment to: Please send me: 4.jsp files that show the design of the original output table and each of the 3 modifications Extra credit: 3.jsp files that show the modification of the bad multiplication table to produce the 3 modifications

Group-ID Rule We frequently wish to process groups in a file sorted by group. Problem: Census file is sorted on a household number. Data for each household is to be accumulated. Detailed problem statement 1.System diagram 2.Data structures for: –input - censusFile.jsp –output - censusReport.jsp 3.Composite data model showing correspondences 4.Basic Program Structure - censusBasicStr.jsp 5.List and allocate operationsList and allocate operations 6.Produce elaborated program structure - censusElabStr.jsp 7.Generate structure text or code Structure text Java code

Group ID Rule Group-id Rule: “If a structure contains a component that is a group of records all having the same value of a (usually sorted) identifier, then there must be an operation that stores the value of the identifier. This operation should be allocated once per group, at the beginning of the group.” Design focuses on: –a static not a dynamic view of the problem; –data structures (objects), not on dynamic flow of control

Homework #2 (due 28 October) The Census household problem is modified as follows: (The course page has a sample file, censusFile.txt in the HW#2 folder. Test your program with this file.) The census text file has a city code in positions Accumulate the total number of males and females as well as the average household size in each city and produce the summary as before. Put sensible column headings in the report: (Household Id, # Males, # Females, etc.) Use Scanner and printf for reading and writing.

Using the Scanner utility class Scanner is in the util package, not the lang package so you need to include the line import.util.Scanner; at the top of the class. To create a Scanner object and connect it to a file you must create a File object based on the name of that file. This can be done with one line; Scanner s = new Scanner( new File(“census.txt")); Remember all programs are judged assuming the file is in the same directory as the compiled class file so do not put any path information on the file, just the file name. To use the file class you must include the line import.io.File; at the top of your program.

Using the Scanner utility class (cont.) Unfortunately instantiating a File object can result in in an IOException and this is a checked exception so you either have to use a try-catch block or declare that the method that contains the code that generates the checked exception throws an IOException. – In actual programming practice it would be much better to include a try-catch block, but for educational purposes and programming contest purposes it is much easier to simply declare that main throws an IOException. –Thus the declaration of the main method looks like this: public static void main(String[] args) throws IOException IOException must also be imported. This can either be done as a separate import statement: import java.io.IOException; or since the program now needs multiple classes from the io package we can use the wildcard import. Again, not the best programming practice, but for Olympiads, not a bad idea. import java.io.*;

Java I/O with Scanner and Formatter Java documentation Tutorial on printf Printf.demo.java Tutorial on Using Scanner for Input from Console ScanConsoleApp.java