Docsity

Introduction to Objects in CMPSCI 121, Spring 2009 - Prof. Erik Learned-Miller, Assignments of Computer Science

Partial preview of the text

Download Introduction to Objects in CMPSCI 121, Spring 2009 - Prof. Erik Learned-Miller and more Assignments Computer Science in PDF only on Docsity!

More on Objects

February 10, 2009 CMPSCI 121, Spring 2009 Introduction to Problem Solving with Computers Prof. Learned-Miller

Supplemental Instruction

 Instructor: Andrew Chan  Two Sessions per week  Wednesdays: 6:45-8:00 PM  Sundays: 8:45-10:00 PM  Location: Library, room 1049

Logistics

The Bulletin Board

 Instructions under “resources”  http://bb-edlab.cs.umass.edu/cs121_S09/  Off-campus access:  Username: cs  Password: elM121cs  Get an account:

Assignment tip

 If you're using a class (like Infant), the code for that class should be in the current directory.

Declarations and Types

 int x;  String name;  Infant emmaLM; // an object!!!  Types  int  String  double  Infant  char  EriksFancyTaxForm

Combining declarations and

assignments

 int x = 3;  String name = “Erik”;  Infant emmaLM = new Infant(“Emma”,0);

Back to objects

 Creating objects with new command  Attributes  Methods  Calling methods with values  Calling methods without values

12 Designing a container Making an instance Storing info Retrieving stuff Storing stuff Using the instance Using the instance Declaring an instance Specifying a class Retrieving info Other methods A new class of briefcases Change infant age Store Infant age Make an instance: myKid Define “Infant” Class Fill briefcase with stuff Create one briefcase And take stuff out

Creating objects with new

new Infant(“Lizzie”,4); new Infant("baby", 7); new Infant(3,"bobbie"); // error new Infant("Lizzie"); // error

Creating objects with new

Infant lizzie = new Infant(“Lizzie”,4); Infant baby = new Infant("baby", 7); Infant bobbie = new Infant(3,"bobbie"); // error Infant lizzie = new Infant("Lizzie"); // error

Creating objects with new

Car hotrod = new Car("Chevy",10,5);

High Tech Folder Demo: Part 1

 Create some objects

Attributes

 Data stored in your object:  Name  Age  make of car  Picture of a person  Other objects  Anything at all you want to store about an object!!!