Lab 1 City, Robot, Thing, Wall. Documentation of Classes and Methods.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

For(int i = 1; i
1 Scanner objects. 2 Interactive programs We have written programs that print console output. It is also possible to read input from the console.  The.
Computer Programming Lab(5).
Shorthand operators.
Extending the Robot Programming Language In the Robot world 1 mile = 8 blocks Suppose we want a robot to run a marathon (26+ miles)? Does our program have.
9/12/2015IT 2751 IDE ( Integrated Development Environment ) 1.A customized plain text editor 2.Compiler 3.Loader 4.Debugging tool JDK (Java Development.
Introduction to Objects A way to create our own types.
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
Lecture 6 Instructor: Craig Duckett. Assignment 1, 2, and A1 Revision Assignment 1 I have finished correcting and have already returned the Assignment.
1 Operators and Expressions Instructor: Mainak Chaudhuri
A Revamping Of our skills so far. Our Tools so Far Variable - a placeholder for a value Method - a set of code which accomplishes a task Class - a mold.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
1/16/2008ITK 1681 HardwareSoftware Theory 1800 AD  Architecture 1945 AD  What is Computer Science? Languages 1960 AD 
ICBT  Basura Ramanayaka  Eshani werapitiya  Hasitha Dananjaya.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
Chapter 2 Creating a Java Application and Applet.
Java Programming Final Keyword In Java. final keyword The final keyword in java is used to restrict the user. The final keyword can be used in many context.
For Friday Finish reading chapter 2 Complete WebCT quiz.
AP Computer Science A – Healdsburg High School 1 Unit 2 - Object-Oriented Programming - Example.
Constructor OverloadingtMyn1 Constructor Overloading One context in which you will regularly need to use overloading is when you write constructors for.
Copyright 2010 by Pearson Education Homework 9: Critters (cont.) reading: HW9 spec.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Errors, GUIs, and Patterns Dr. Doug Twitchell August 30, 2005.
Review – Primitive Data What is primitive data? What are 3 examples of primitive data types? How is a piece of primitive data different from an object?
Lecture 11 Instructor: Craig Duckett Instance Variables.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Staples are our staple Building upon our solution.
1/28/2008ITK 1681 An enhanced robot Robot int street int avenue Direction direction ThingBag backback Robot(City aCity, int aStreet, int anAvenue, Direction.
For Monday Read Becker, chapter 4, sections 1 and 2.
Java Methods and Applications CSIS 3701: Advanced Object Oriented Programming.
Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
GC211 Data structure Lecture 3 Sara Alhajjam.
“Packages in Java”.
Building Java Programs
using System; namespace Demo01 { class Program
Robot Class name Attributes Constructor Services, methods
Interface.
Polymorphism and Observers
Something about Java Introduction to Problem Solving and Programming 1.
Computing Adjusted Quiz Total Score
Interface.
import becker.robots.City;
Unit 1 Lab16.
Code Animation Examples
References, Objects, and Parameter Passing
Recursive GCD Demo public class Euclid {
ITK 168 Section 13 Dr. Doug Twitchell.
Sampath Kumar S Assistant Professor, SECE
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Java Programming with Multiple Classes
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
if-else if (condition) { statements1 } else { statements2
Scope of variables class scopeofvars {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
while while (condition) { statements }
Sampath Kumar S Assistant Professor, SECE
Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists.
Homework 9: Critters (cont.)
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
IDE (Integrated Development Environment)
Consider the following code:
ITE “A” GROUP 2 ENCAPSULATION.
Presentation transcript:

Lab 1 City, Robot, Thing, Wall

Documentation of Classes and Methods

City Class  Constructs a city that the robot will move in it. City newYork = new City();

Robot Class  Constructs a Robot to move in the city. Robot hal = new Robot(newYork, 1, 2, Direction.SOUTH);

Thing Class  Constructs a thing that can be put in a city. Thing t1 = new Thing(newYork, 2, 2);

Wall Class  Constructs walls in the city to block robots. Wall wa = new Wall(newYork, 3, 3, Direction.WEST);

Methods in Robot Class

Methods in Thing Class

Classes in becker Library

Example 1 package rob; import becker.robots.*; public class Rob extends Object { public static void main(String[] args) { // Declare the objects needed City newYork = new City(); Robot hal = new Robot(newYork, 1, 2, Direction.SOUTH); Thing t1 = new Thing(newYork, 2, 2); Wall wa = new Wall(newYork, 3, 3, Direction.WEST); Thing t2 = new Thing(newYork, 3, 2); Thing t3 = new Thing(newYork, 4, 2); hal.move(); hal.pickThing(); hal.move(); hal.pickThing(); hal.move(); hal.pickThing(); hal.move(); hal.putThing(); hal.move(); }

Example 2 package rob; import becker.robots.*; import becker.robots.icons.*; import java.awt.Color; public class Lamp extends Thing {public Lamp(City aCity, int aStreet, int anAvenue) {super(aCity, aStreet, anAvenue); this.turnOn(); } public void turnOn() { Color onColor = new Color(255, 255, 200); CircleIcon onIcon = new CircleIcon(onColor); onIcon.setSize(0.75); this.setIcon(onIcon); } public void turnOff() { Color offColor = new Color(0, 0, 0); CircleIcon offIcon = new CircleIcon(offColor); this.setIcon(offIcon); }

Cont.. Example 2 package rob; import becker.robots.*; public class Main { public static void main(String[] args) { // Construct the initial situation. City paris = new City(); Lamp lamp1 = new Lamp(paris, 1, 1); Robot lampMover = new Robot(paris, 1, 0, Direction.EAST); // Use the robot to move one of the lamps. lampMover.move(); lampMover.pickThing(); lampMover.move(); lampMover.putThing(); lampMover.move(); lamp1.turnOff(); }