1 / 17

Jeroo – Chapter 4 –

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

gavril
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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Jeroo – Chapter 4 – Simple Programs

  2. 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.

  3. 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

  4. 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 ( ) { ……. }

  5. 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

  6. 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.

  7. 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

  8. Our code so far method main ( ) { Jerooname= new Jeroo(…); }

  9. Instantiation Portion Now we will look at the code in red Method main () { Jeroojessica = new Jeroo(…) }

  10. 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?

  11. 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.

  12. Syntax of an action statement jessica.hop(3)

  13. 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

  14. What happens in the following code? Method main ( ) { Jerooplace = new Jeroo (); place.hop(4); place.turn(RIGHT) place.hop(2); place.plant();

  15. 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?

More Related