Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Class code

No description
by

Mark Coleman

on 5 November 2015

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Class code

Class code
The data (What's it know?)
Class variables are declared following the ClassName

private
dataType

variableName
;

Class variables are ALWAYS marked private

As usual, MUST declare a dataType

Do NOT give a class variable a value
There are a few exceptions to this rule, we'll talk about them later
The name
ALWAYS starts with:

public class
ClassName
{
class code
}

Classes are ALWAYS public

ClassName ALWAYS starts with an uppercase letter
Methods (What's it do?)
There can be as many methods as needed

public
returnType

methodName
(
parameters...
)
{
method code
}

Methods are ALWAYS public
returnType
= the dataType returned by the method
Either a normal data Type (int, double, boolean, String)
Or, void - doesn't return anything
Example: find area method would return a double
Example: set width method would return void (nothing)
methodName
follows variable naming rules
The constructor (How's it made?)
This runs when an object is created
It's purpose is to give values to all the class variables

public
ClassName
(
parameters...
)
{
constructor code
}

ClassName MUST match your class's name exactly
We'll talk about parameters in a couple of slides...
Basic class code stucture
public class
ClassName
{
private
dataType

variableName
;
<repeat variables as needed>

public
ClassName
(
parameters...
)
{
constructor code
}

public
returnType

methodName
(
parameters...
)
{
method code
}

<repeat methods as needed>
Red denotes the parts you must change
No semicolon
Parameters
A parameter is a piece of data that is needed by the constructor or method.
There can be none, one, or as many parameters as necessary
They ALWAYS go in the parenthesis following the method name, each has a data type and are broken up by commas

Example:
Draw a rectangle with a width of 3.7 and height of 9.1
In this case, 3.7 and 9.1 would be the parameters
a double and a double
Rectangle(double w, double h)

Change the rectangles height to 42.0
In this case, 42.0 is the only parameter
a double
setHeight(String sn)

Display the area of the rectangle
In this case, there are NO parameters needed
area()


Method code
The code inside a method is just regular code
Any number of variables can be defined in a method
Don't use the same name as your class variables
These will only exist in the method

One new piece of code:

return

This is only used in a method that will return a value (get the rectangle's area, get a circle's radius, etc.)
MUST be the last line of code
MUST have some value/variable/operation after
Example:
return 42;
return area;
return width * height;
Full transcript