Jeroo chapter 4
This presentation is the property of its rightful owner.
Sponsored Links
1 / 17

Jeroo – Chapter 4 – PowerPoint PPT Presentation


  • 91 Views
  • Uploaded on
  • Presentation posted in: General

Jeroo – Chapter 4 –. Simple Programs. Basic Concepts. Jeroo (Java/C++/object-oriented) programing style is case- sensative . Be consistent in coding Logic must be well designed Must be easy for someone to read and understand the program’s source code

Download Presentation

Jeroo – Chapter 4 –

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Jeroo chapter 4

Jeroo – Chapter 4 –

Simple Programs


Basic concepts

Basic Concepts

Jeroo (Java/C++/object-oriented) programing style is case-sensative.

Be consistent in coding

Logic must be well designed

Must be easy for someone to read and understand the program’s source code

Whitespace, comments, and descriptive identifiers all contribute to making a program easier to read.


Basic concepts1

Basic Concepts

  • Whitespace – consists of blank lines, spaces, tabs

    • Should be used to organize code into groups

    • Comments are phrases that a programmer inserts into a program to provide anyone who reads it additional information (Just like HTML)

      • Ignored when the program is run

      • Begins with // and continues until the end of the line


Form of a jeroo program main method

Form of a Jeroo ProgramMain Method

The main method describes how to use one or more Jeroos to solve a specific problem.

Everything that appears between the braces should be indented 2 or 3 spaces.

Method main ( )

{

…….

}


Declaring and instantiating jeroos

Declaring and Instantiating Jeroos

  • Every Jeroo program uses 1 to 4 Jeroo objects to solve a problem.

  • First declare the Jeroo, then Instantiate the Jeroo

    Jeroo name= new Jeroo(…);

  • For the declaration, the programmer must provide a name for the Jeroo object.

    • First character must be a letter, $, or underscore (_)

instantiation

declaration


Declaring and instantiating jeroos1

Declaring and Instantiating Jeroos

  • Instantiation

  • A request that the Jeroo object be created

  • The crucial part is the constructor, which has the form of:

    • Jeroo (…)

  • The parentheses are filled with the initial values of the attributes for the Jeroo

  • Every Jeroo has 3 attributes: location, direction, number of flowers in its pouch.


Declaring and instantiating jeroos2

Declaring and Instantiating Jeroos

  • If the initial values are not specified, then the constructor provides the default values:

    • Location – (0,0)

    • Direction – East

    • Flowers -- 0


Our code so far

Our code so far

method main ( )

{

Jerooname= new Jeroo(…);

}


Instantiation portion

Instantiation Portion

Now we will look at the code in red

Method main ()

{

Jeroojessica = new Jeroo(…)

}


Now our code

Now our code…..

Method main ()

{

Jeroojessica = new Jeroo(2,5,North,4)

}

What is the default location?

How many flowers does Jessica have?

What direction is Jessica facing?


4 4 action statements

4.4 Action Statements

  • Is a request that a Jeroo perform a specific task.

  • The task can be either:

    • One of the basic action methods that are part of the Jeroo language

    • OR a Jeroo method that has been written by the program

  • We will concentrate on ones that are part of the Jeroo language.


Syntax of an action statement

Syntax of an action statement

jessica.hop(3)


Syntax of action statement

Syntax of Action Statement

The Jeroo language inclues the 7 action methods shown on the next slide(s).

Three (3) of these: give, turn, hop require an argument value.

On the next slide, we will look at a table of actions


What happens in the following code

What happens in the following code?

Method main ( )

{

Jerooplace = new Jeroo ();

place.hop(4);

place.turn(RIGHT)

place.hop(2);

place.plant();


Answer these questions about the code

Answer these questions about the code?

What are the final coordinates of Jeroo place?

There is a logic error in the code. What is it?

There are two syntactical errors in the code. What are they?


  • Login