1. Ett problem/uppgift. Turtle =========== xPos: int yPos: int direction: double bodyColor: Color name: String.... ---------------------- forward(int):

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

2I1073 Lektion 2 KTH-MI Peter Mozelius Servlets, säkerhet, och filhantering.
Trådad Echo server public class ThreadedEchoServer extends Thread { Socket con; public static void main(String[] args) {... try { ServerSocket ss = new.
IV1351 ht2010 nikos dimitrakas KTH/ICT/SCS 1 Embedded SQL i Java nikos dimitrakas rum 6626 Connolly/Begg(3rd edition) Kapitel 21.
1. Ett problem/uppgift. Turtle =========== xPos: int yPos: int direction: double bodyColor: Color name: String forward(int):
 I engelska måste du ha med do i frågor och nekande meningar (med not) som inte innehåller något hjälpverb (t.ex. be, have, must, can, shall, will).
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
ITK:P1 Lektion 2 Klassarv, polymorfism och grafiska komponenter DSV Peter Mozelius.
CMOS-inverterare Vi använder ett ”gammalt” chip – och behöver välja tillverkningsparametrarna därefter!  Kommer Du ihåg inverteraren från Digital Design.
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
C#: Udtryk og metoder. Indhold “With regards to programming statements and methods, C# offers what you would come to expect from a modern OOPL…” Udtryk.
Övning 5. Repetition klasser class Rektangel { private static int antal = 0; private double längd; private double bredd; public Rektangel(double l, double.
TOPIC 12 CREATING CLASSES PART 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
1 Lecture Today’s Topics Classes –Attribute (variables) –Behaviors (methods) Using methods –How to write methods –How to use methods Scope –Private.
Lecture 6. What is the difference in pictures ???
Lecture 5. Review (Attributes and Methods) Class will contain –a set of attributes and methods public class Turtle { ///// Field (Attributes) ///// …
1 BUILDING JAVA PROGRAMS CHAPTER 3 THE SCANNER CLASS AND USER INPUT.
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
UML Basics & Access Modifier

TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Methods in Java CSC1401. Overview In this session, we are going to see how to create class-level methods in Java.
Copyright © Curt Hill Turtles The beginning of media computation.
CS 121 – Intro to Programming:Java - Lecture 7 Announcements A new Owl assignment is available. Programming assignment 4 is due on Thursday - hand in on.
SD2071 Games Programming Abstraction, inheritance and interfaces Exceptions Two dimensional arrays Java collections framework Files Aaron Kans.
© A+ Computer Science - Chicken yeller = new Chicken();
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
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.
Chapter 2 Creating a Java Application and Applet.
Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design.
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Import javax.swing.JOptionPane; public class Rectangle { public static void main(String[] args) { double width, length, area, perimeter; String lengthStr,
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Web & Systems Developer, 30 credits
7 Class documentation and libraries
OBJECT ORIENTED PROGRAMMING
Objektorienterade applikationer d2, förel. 6
Elmotorstyrning Av Nicklas Adeson S. / Gymnasielärare1.
using System; namespace Demo01 { class Program
More methods, more capabilities
Interface.
Computer Programming Methodology File Input
Function Call Trace public class Newton {
Functions Used to write code only once Can use parameters.
Computing Adjusted Quiz Total Score
TO COMPLETE THE FOLLOWING:
2 The anatomy of class definitions
Unit-2 Objects and Classes
Java Lesson 36 Mr. Kalmes.
Code Animation Examples
Recursive GCD Demo public class Euclid {
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Methods Again Parameter Passage
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.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
Methods/Functions.
Entergates Utbildningspaket HR
The beginning of media computation Followed by a demo
Methods Coding in Java Copyright © Curt Hill.
Presentation transcript:

1. Ett problem/uppgift

Turtle =========== xPos: int yPos: int direction: double bodyColor: Color name: String forward(int): void backwark(int):void setName(String)..... World ============ width: int height: int background:Color newColor(Color) Ett problem/uppgift 2. Beskriv de typer av objekt som finns i klassdiagram. Klassdiagrammet har (liksom klassen) två huvuddelar: - instansvariabler med typ - metoder med parameterlista och returtyp

public class World { private int height; private int width; private Color background; public World(int w, int h) {.... } public setColor(Color newC) { background = newC; }..... } Import java.util.*; public class Turtle { private int xPost; private int yPos private double direction; private Color bodycolor private String name; public Turtle(World w) {.... } public setName(String newName) { name = newName; }..... } 3. Implementera (koda) klasserna. Spara i filer, t ex Turtle.java

. public class World { private int height; private int width; private Color background;... public World(int w, int h) {.... } public setColor(Color newC) { background = newC; }.... } World w = new World(400,400); Turtle t1 = new Turtle(w); Turtle t2 = new Turtle(w); Turtle t3 = new Turtle(w); t1.turn(90); t1.forward(100); t2.forward(70); 4. MEN: vi måste skapa objekt och anropa metoder, annars händer inget { public class Turtle { private int xPost; private int yPos private double direction;.... public Turtle(World w) {.... public setName(String n) { name = n; }..... }

public class TurtleTest { public static void main(String[] arg) { World w = new World(400,400); Turtle t1 = new Turtle(w); Turtle t2 = new Turtle(w); Turtle t3 = new Turtle(w); t1.turn(90); t1.forward(100); t2.forward(70); } 5.Satserna skall ligga i en speciell metod som skall heta main. Lägg main-metoden i en egen klass, T ex TurtleTest. 6. Kompilera alla klasserna => - kompilatorn testar om syntaxen är korrekt - Sen översätts koden till java- Bytekod (class-filer) public class Turtle { private int xPost; private int yPos private double direction;.... public Turtle(World w) {.... }..... } public class World { private int height; private int width; private Color background;... public World(int w, int h) {.... }.... }

7. Nu kan vi köra filen som innehåller main-metoden. > run TurtleTest