1 CS1110 Lecture 09 28 Sept Developing (String-processing) programs; class Vector; wrapper classes Prelim: 7:30-9PM Thursday 7 October. Last name A-K:

Slides:



Advertisements
Similar presentations
1 CS1110 Lecture 23, 18 Nov 2010 Listening to GUIs Reading for today: Ch , [ Optional: Ch & (interfaces)] For next lecture:
Advertisements

1 CS Sept. Customizing a class & testing Quiz 2 on Tuesday 15 Sept Purpose of a constructor (slide 5) Evaluating a new expression (slide 6) Fields;
1 CS1110 Stepwise refinement, wrapper classes 29 Sept Prelim: 8PM Thursday 8 October (next week) If you have a conflict and have not been contacted, .
For use of Cleveland State's IST410 Students only 1 Vectors and Collections.
CS100J 11 September 2003 Course Management System for CS100J is now populated with students who were pre-registered. Look at course web page to see how.
CS 1110 Prelim I: Review Session. Exam Info Prelim 1: 7:30–9:00PM, Thursday, 6 October, Statler Auditorium Look at the previous Prelims Arrive early!
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
1 CS100J 18 September 2007 More on Methods. Developing methods. Also: The inside-out rule; and the use of this and super. Read sec. 2.5 on stepwise refinement.
Inheritance and interfaces A class C1 is derived from class C2, then C1 is called subclass, and C2 is called superclass Superclass-parent, base class Subclass.
1 CS100J 20 September 2005 More on Methods. Developing methods Also: About the use of this and super Read section 2.5 on stepwise refinement Listen to.
Static Class Members Wrapper Classes Autoboxing Unboxing.
1 CS100J 30 January 2007 The class definition Course Management System (CMS) for CS100J is populated with students who were pre-registered. Look at course.
Comparing Objects in Java. The == operator When you define an object, for instance Person p = new Person("John", 23); we talk about p as if its value.
1 CS1130 Spring 2011: David Gries & Walker White Transition to Object-Oriented Programming Assumes programming knowledge in a language like Matlab, C,
1 CS1110 Fall 2011: David Gries & Steve Marschner CS1112: Matlab No prior programming experience One semester of calculus Math- & engineering- type problems.
Quote for the day: Computational thinking: a fundamental skill for everyone … [It] is … choosing an appropriate representation for a problem or modeling.
Chapter 11 Abstract Classes and Interfaces 1. Abstract method New modifier for class and method: abstract An abstract method has no body Compare: abstract.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
Class Library, Formatting, Wrapper Classes, and JUnit Testing
Quote for the day: Computational thinking: a fundamental skill for everyone … [It] is … choosing an appropriate representation for a problem or modeling.
1 CS1110 Wrapper classes, stepwise refinement 27 Sept Prelim: Tuesday, 6 Oct, 7:30–9:00PM, Statler Auditorium Thursday: no reading. Be there or be square.
1 CS Sept 2010 Customizing a class Quote for the day: I have traveled the length and breadth of this country and talked with the best people, and.
CS1110 lecture 5 14 Sept 2010 Testing; the class Object; toString; static variables & methods Reading for this lecture: Testing with JUnit (Appendix I.2.4.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
CS100J Spring 2006 CS100J: 11 weeks of programming using Java and 2 weeks using Matlab. David Gries is teaching CS100J. Graeme Bailey is teaching a special.
1 CS1110, 8 March 2009 Two topics: elementary graphics (for A5); loops Reading: Sec and chapter 7 on loops. The lectures on the ProgramLive CD can.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
1 CS Sept 2010 Inside-out rule; use of this, super Developing methods (using Strings). Read sec. 2.5, stepwise refinement Listen to Plive, 2.5.1–2.5.4.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
1 CS100J Wrapper classes, stepwise refinement 19 Feb When insults had class "A modest little person, with much to be modest about." Churchill "I never.
1 CS1110 lecture 4 9 Sept. Customizing a class & testing Classes: fields; getter & setter methods. Secs (p. 45) & 3.1 (pp. 105–110 only) Constructors.
Some Standard Classes Goals The Object class The String class Wrapper classes The Math class Random Numbers.
Programming in Java (COP 2250) Lecture 8 Chengyong Yang Fall, 2005.
Introduction to Java COM379 (Part-Time) University of Sunderland Harry R Erwin, PhD.
CSC 142 Computer Science II Zhen Jiang West Chester University
1 CS1100 Fall Instructor: David Gries CS100M: Matlab No prior programming experience One semester of calculus Math & engineering type problems CS100J:
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
1 CS100J Classes, stepwise refinement 14 Feb 2007 Rsrecah on spleilng Aoccdrnig to a rscheearch at Cmabirgde Uinervtisy, it deosn't mttaer in waht oredr.
Using Classes and Objects. We can create more interesting programs using predefined classes and related objects Chapter 3 focuses on: Object creation.
CSC 1051 M.A. Papalaskari, Villanova University Everyday objects: Strings and Wrappers CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari.
1 CS1110 Wrapper classes, stepwise refinement 30 September Chocolate bar has grooves that divide it into squares. This is one example. Others would be.
© 2004 Pearson Addison-Wesley. All rights reserved September 7, 2007 Formatting Output & Enumerated Types & Wrapper Classes ComS 207: Programming I (in.
CONTENTS Wrapper Class Enumeration Garbage Collection Import static.
1 CS1110 Stepwise refinement, more on classes 24 Sep 2009 Application of String processing and stepwise refinement. Miscellaneous points about classes.
1 CS1110 Classes, stepwise refinement 17 Feb 2009 Miscellaneous points about classes. More on stepwise refinement. Next: wrapper classes. Section 5.1 of.
TeachJava! 2003 Corky Cartwright Dung Nguyen Stephen Wong Charlie Reis, James Hsia, Peter Centgraf.
1 CS September 2008 Discussion of Methods: Executing method calls.If-statements. The return statement in a function. Local variables. For this and.
Outline Creating Objects The String Class Packages Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Chapter 3: Using Classes and Objects Coming up: Creating Objects.
Wrapper Classes  Java offers a convenient way to incorporate, or wrap, a primitive data type into an object, for example, wrapping int into the class.
1 CS1110 Classes, stepwise refinement 12 Feb 2009 Rsrecah on spleilng Aoccdrnig to a rscheearch at Cmabirgde Uinervtisy, it deosn't mttaer in waht oredr.
Attribute - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 12/24/2016.
1 CS1110 lec 12: Analysis of lies using recursion 07 Oct 2010 Prelim, 7:30-9pm today Last name A-K: go to Olin 155 Last name L-Z: go to Olin 255 A4 due.
Wrapper Classes Use wrapper objects in Collections when you can’t use primitive types Primitive TypeWrapper Class byteByte shortShort intInteger longLong.
1 CS100J Spring Instructor: David Gries CS100M: Matlab No prior programming experience One semester of calculus Math & engineering type problems.
CS/ENGRD 2110 FALL 2013 Lecture 3: Fields, getters and setters, constructors, testing 1.
1 CS Sep 2011 Miscellaneous points about classes. More on stepwise refinement. Next: wrapper classes. Section 5.1 of class text Need Help? Make.
1 CS February 2009 Inside-out rule; use of this and super Developing methods (using String ops). Read sec. 2.5 on stepwise refinement Listen to.
1 CS Sept 2010 Customizing a class Quote for the day: I have traveled the length and breadth of this country and talked with the best people, and.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
© 2004 Pearson Addison-Wesley. All rights reserved January 27, 2006 Formatting Output & Enumerated Types & Wrapper Classes ComS 207: Programming I (in.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
1 CS Sept Customizing a class & testing Quote for the day: There is no reason anyone would want a computer in their home. - -Ken Olson, founder.
1 CS1110 Classes, wrapper classes, Vectors. 10 Feb 2012 Miscellaneous points about classes. Discussion of wrapper classes and class Vector Use the text.
CS Feb 2010 Customizing a class
More About Objects and Methods
CS1110 Classes, stepwise refinement 23 Sep 2009
Chapter 10 Thinking in Objects
CS1110 Wrapper classes, stepwise refinement 23 Feb
CS Feb 2011 Customizing a class
Presentation transcript:

1 CS1110 Lecture Sept Developing (String-processing) programs; class Vector; wrapper classes Prelim: 7:30-9PM Thursday 7 October. Last name A-K: go to Olin Hall 155. Last name L-Z: go to Olin Hall 255. If you have a conflict and didn't receive an acknowledgment yesterday, Maria Witlox, TODAY. Past prelims are posted to the course website. Use DrJava to check your answers! Thursday: A handout will explain what is on prelim 1 Sunday: Review session, 1-3PM, Phillips Hall 101 (if you miss it, the slides will be posted) A3 is due Wed night on the CMS. Form any groups beforehand. Reading for Thursday's lecture: pp. 403—408, skipping section * Recursion can be a difficult topic, but we’ll make it easy. Have your iClickers out.

2 An application: String processing, stepwise refinement, usefulness of Javadoc, problem solving Strings are a particularly important type, because lots of information (especially non-numerical data) is stored in Strings. For example, many webpages can, for many intents and purposes, be considered to be Strings. Application: “scraping” (extracting) live stock quotes from the Web: getQuote("goog") will print out Google's [ticker symbol: "GOOG"] current stock price, and store a list of all previous stock-price requests; showRecord() will return something like this: Mon Sep 27 10:00:40 EDT 2010: $294.05, Mon Sep 27 10:00:48 EDT 2010: $293.7, Mon Sep 27 10:09:02 EDT 2010: $534.38]"

3 Reminder: Principles and strategies Develop algorithm step by step, using principles and strategies embodied in “stepwise refinement” or “top-down programming”. READ Sec. 2.5 and Plive p Take small steps. Do a little at a time Refine. Replace an English statement (what to do) by a sequence of statements to do it (how to do it). Refine. Introduce a local variable —but only with a reason Compile often Intersperse programming and testing Write method specifications —before writing the bodies Separate your concerns: focus on one issue at a time Note the similarities to outlining and writing an essay!

4 1.What information do we need to store? what objects? what should be in the objects, vs. what should be static? What types should the variables be? 2.What methods do we need? (Specify them carefully, and stub them in!) a) How do we implement a list? (answer: Vectors) a)How do we implement list-based methods? b)How do we actually get stock-quote data? i.how can we access web pages? ii.can we treat their contents as Strings, since we're good at that? iii.how can we convert String prices to numbers? (answer: Wrapper classes) Outline for writing class StockQuote

5 Let's answer question one. Below, we've omitted "private" for brevity. A. String symbol; // ticker symbol (case insensitive) Date time; // time the quote was taken; double price; // price of the stock when quote was recorded ListOfStockQuotes record; // list of all requested quotes public static void getQuote(String s); B. Same as A, but getQuote(String s) is not static C. String symbol; // ticker symbol (case insensitive) Date time; // time the quote was taken; double price; // price of the stock when quote was recorded static ListOfStockQuotes record; // list of all requested quotes public static void getQuote(String s); D. Same as C, but getQuote(String s) is not static E. None of the above C's only diff from A

6 In the interactions pane, you can try the following (Person.java and StockQuote.java need to be in the working directory and compiled) : import java.util.*; import javax.swing.*; Vector v= new Vector(); // v can store any object v.add(new JFrame()); v.add(new Person("Smith", 1990, false)); v.get(1) // returns (toString for) "Smith" object (indexing starts at 0) v.toString() // contents of entire vector, using each object's toString() Class Vector – for maintaining lists of objects [more in lab] // Important syntax: record can only store (names of) StockQuotes. Vector record= new Vector ();

7 Wrapper classes – a way to treat primitive types as objects An instance of class Integer contains, or "wraps", one (immutable) int value. a0 [unknown field name] 5 Integer(int) Integer(String) toString() equals(Object) intValue() toString(int) toBinary(int) valueOf(String) parseInt(String) Static components: MIN_VALUE MAX_VALUE file drawer for Integer Integer Sometimes objects are required; e.g., Vectors can only store objects: v.add(new Integer(5)); // Integer is an object version of int wrapper objects provide a place to store useful methods [In newer versions of Java, v.add(5) is allowed; the non-object 5 is wrapped in an Integer object and the name of that object is added to v.]

8 Each primitive type has a corresponding wrapper class. Primitive typeWrapper class intInteger longLong floatFloat doubleDouble charCharacter booleanBoolean Each wrapper class has: Instance methods, e.g. equals, constructors, toString, Useful static constants and methods. You don't have to memorize the methods of the wrapper classes. But be aware of them and look them up when necessary. Use Gries/ Gries, Section 5.1, and ProgramLive, 5-1 and 5-2, as references. Integer k= new Integer(63); int j= k.intValue();