You are on page 1of 15

Components

of a Code
Basic How To

Calling a Program
For the first program you guys created ( the house model ). You guys
declared one class called DrawSquare.
Inside of this class we setup a method called main.
From this main method, the DrawSquare created a SketchPad named
paper. We set the size of this paper to something like 300 by 300 [(the
measurements for this size is in pixels) and (the size could have been
different for each person, meaning that the 300 by 300 is not default,
it's just what we used)]

To Start making things


We used the DrawingTool class and created the object pencil, then
preceded to give the pencil a sequence of messages to draw the house.

Comments
comments are created by applying two different notations
/*This style will allow you to write longer documentation
the text can wrap around to succeeding lines. */

// This style automatically ends at the end of the line.

notes as

Import packages
As simple as learning how to write your name.
you type the word import in the beginning of the line then add a
space and type the name of the file. Immediately after the name of the
file add an * and end the line with a semicolon.

Class
When you use the word class you are marking the beginning of a class
declaration.

modifiers
the modifiers refers to a sequence of terms designating different kinds
of methods.

return_type
The return_type refers to the type of data a method returns.
You can use this on predefined types or a user-defined type.

Declaration
class_name object_name;
a.class_name is the name of the class to which these objects belong
b.object_name is a sequence of object names separated by commas

Creation
An object is not actually created when you declare it. An object is
created by using the new operation.
object_name = new class_name(arguments);
a.object_name is the name of the declared object
b.class_name is the name of the class to which the object belongs
c. arguments is a sequence of zero or more values passed to the new
operation
paper = new SketchPad(300,300);

Message Sending
You can only send a message after the object is created.
object_name.method_name(arguments);
a.object_name is the name of the declared object
b.methid_name is the name of a method of the object
c. arguments is a sequence of zero or more values passed to the
object

Recap
The Difference Between Objects and Classes

A class
is a template that defines attributes and methods
is written by a programmer as a part of a program
does not exist when programs execute, except in the form of one or
more member objects
its code cannot be altered during program execution
it's named by a class name

object
must belong to some class
exists during the time that a program executes
must be explicitly declared and constructed by the executing program
has attributes that can change in values and methods that can execute
during program execution
is often referenced using a variable name

Assignment
1.Check the website or come see us if you missed a meeting.
2.Continue working on your house if you have not completed it.
3.Build a Benzene model. A Benzene model
organic compound. Its chemical

is an
formula is C6H6.

You might also like