Phil Campbell London South Bank University Using Java (2)

Slides:



Advertisements
Similar presentations
Introduction to classes Sangeetha Parthasarathy 06/11/2001.
Advertisements

Decompilation of.NET bytecode Stephen Horne Trinity Hall 10 th February 2004 Computer Science Part II Project Progress Report
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.
1 Arrays, Strings and Collections [2] Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Southern Regional Education Board Nebraska Accreditation Requirements Mission/vision statement Collect and analyze data Improvement goals Develop and.
Opportunities for Gigascale Integration in Three Dimensional Architectures James Joyner, Payman Zarkesh-Ha, Jeffrey Davis, and James Meindl Microelectronics.
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
Object Oriented Programming with Java
Color Templates Software Engineering Module: Core of Java Topic: Constructors TALENTSPRINT | © Copyright 2012.
Investigating the Heating and Cooling Rates of Soil and Water Lab
Looking inside classes Fields, Constructors & Methods Week 3.
Java
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © Recursive GCD Demo public class.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
1 Arrays An array is a special kind of object that is used to store a collection of data. The data stored in an array must all be of the same type, whether.
Phil Campbell London South Bank University Java 1 First Steps.
BBIT 212/ CISY 111 Object Oriented Programming (OOP) Objects and classes, object interactions in Java
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Modification 0466 – Daily Meter Reading Simplification DMM Reads Timeline David Addison.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Polymorphism Method overriding Method overloading Dynamic binding 1.
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.
Visual Classes 1 Class: Bug 5 Objects: All Bug Objects.
Java Programming Abstract classes and Interfaces.
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, toString reading: self-checks: #13-18,
Objects contains data and methods Class – type of object Create class first Then object or instance String – defined class String s; // creates instance.
Building a Linked List in Java. Linked List In the Procedural Paradigm a linked list consisted of: –A pointer to the head of the list –Nodes (in dynamic.
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Web Application Development Slides Credit Umair Javed LUMS.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Övning 4. Repetition göra egna klasser class Rektangel { private double längd; private double bredd; public Rektangel(double l, double b) { this.längd.
FEN KbP: Seminar 2/JML-Intro1 JML Introduktion Specifikation af en Personklasse.
Written by: Dr. JJ Shepherd
Development by Extension Rather than build everything from scratch every time, existing classes should be re-used as much as possible. But existing classes.
Problem!! demoCounter = new LimitedCounter( 10, 12); demoCounter.unCount(); System.out.println( “The value of demoCounter should “ + “always be between.
LimitedCounter - extension & inheritance BasicCounter LimitedCounter Every LimitedCounter instance inherits every resource (attributes & methods) which.
Temperature class diagram. Temperature instances.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
1 OOP : main concepts Polymorphism. 2 OOP : main concepts  The main concepts:  In a superclass –public members Accessible anywhere program has a reference.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Inheritance (Part 4) Polymorphism and Abstract Classes 1.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Inheritance (Part 2) Notes Chapter KomondorBloodHound PureBreedMix Dog Object Dog extends Object PureBreed extends Dog Komondor extends PureBreed.
Inheritance (Part 2) KomondorBloodHound PureBreedMix Dog Object.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 17.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
CO320 Catchup David Barnes with material from Dermot Shinners-Kennedy.
Inheritance, Polymorphism and Abstract Classes. Student Management System All students are CUNY Students CUNY Students are Queens College students, or.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Written by: Dr. JJ Shepherd
Topic: Classes and Objects
Java Memory Management
Java Memory Management
Instance Method Review - CIS 1068 Program Design and Abstraction
CS/ENGRD 2110 Spring 2017 Lecture 5: Local vars; Inside-out rule; constructors
null, true, and false are also reserved.
CS/ENGRD 2110 Fall 2018 Lecture 5: Local vars; Inside-out rule; constructors
مظفر بگ محمدی دانشگاه ایلام
JAVA An Introduction to Java OOP Basics
JAVA CLASSES.
Chapter 11 Inheritance and Polymorphism Part 1
Presentation transcript:

Phil Campbell London South Bank University Using Java (2)

Phil Campbell London South Bank University Temperature

Phil Campbell London South Bank University Temperature

Phil Campbell London South Bank University Temperature

Phil Campbell London South Bank University An object is an instance of a class that has state, behaviour and identity.

Phil Campbell London South Bank University // Filename Temperature.java // // Class to represent a temperature in degrees // centigrade, accurate to 1/10 of a degree. // Fintan Culwin, v0.2, Sept 03. public class Temperature extends Object {

Phil Campbell London South Bank University private double theTemp = 0.0; public Temperature() { this( 0.0); } // End Temperature no-args constructor. public Temperature( double setTo) { super(); theTemp = setTo; } // End Temperature constructor. Temperature - theTemp : double + Temperature( ) + Temperature( setTo: double) + getTemp(): double # setTemp(setTo: double) + toString(): String attribute constructor Call constructor in super class (Object)

Phil Campbell London South Bank University A constructor Places a newly created object into a well defined initial state

Phil Campbell London South Bank University public double getTemp() { return theTemp; } // End The getTemp. public String toString() { return theTemp + " degrees centigrade"; } // End toString. inquiry methods

Phil Campbell London South Bank University protected void setTemp( double setTo) { theTemp = setTo; } // End The setTemp. mutator method Note:

Phil Campbell London South Bank University Thingy - thing : int + Thingy( ) # Thingy( toThis : int) + setThing( toThis :int) + getThing( ) : int + toString( ) : String Object Thingy class Diagram Exercise Write what you would expect to see in Java

Phil Campbell London South Bank University Thingy Object public class Thingy extends Object { }

Phil Campbell London South Bank University Thingy Object public class Thingy extends Object { } - thing : int private int thing;

Phil Campbell London South Bank University Thingy - thing : int + Thingy( ) Object # Thingy( toThis : int) + setThing( toThis :int) + getThing( ) : int + toString( ) : String public Thingy( ){ this( 0); } protected Thingy( int toThis){ super( ); thing = toThis; } public void setThing( int toThis){ thing = toThis; } public int getThing( ){ return thing; } public String toString( ){ return "Value held is " + thing; } concatenation`

Phil Campbell London South Bank University TemperatureDemonstration bodyTempboilingfreezing Temperature creates and shows Object instance of IsA

Phil Campbell London South Bank University 0001 // Filename TemperatureDemonstration.java 0002 // 0003 // Demonstration client for the Temperature 0004 // class // 0006 // Fintan Culwin, v0.1, sept public class TemperatureDemonstration extends Object { 0009 public static void main( String[] args) { Temperature freezing = null; 0012 Temperature boiling = null; 0013 Temperature bodyHeat = null; System.out.println( "\n\nTemperature Demonstration\n\n"); System.out.println ( "This demonstration will construct and display"); 0018 System.out.println ( "Three different instances of the Temp~ class."); System.out.println ( "\nConstrucing... \n ");

Phil Campbell London South Bank University 0025 freezing = new Temperature(); 0026 boiling = new Temperature( 100.0); 0027 bodyHeat = new Temperature( 37.8); 0029 System.out.println( "\nConstructed, showing... \n"); System.out.println( "Freezing is " + freezing.toString() ); 0032 System.out.println( "Boiling is " + boiling.toString()); 0033 System.out.println( "Body Heat is " + bodyHeat); 0034 } // End main } // End TemperatureDemonstration. Constructed, showing... Freezing is 0.0 degrees centigrade Boiling is degrees centigrade Body Heat is 37.8 degrees centigrade

Phil Campbell London South Bank University Thingy - thing : int + Thingy( ) # Thingy( toThis : int) + setThing( toThis :int) + getThing( ) : int + toString( ) : String Object fred : Thingy thing = 5 class instance Make a demo class for a Thingy (first line) Write the start of the main method Create a Thingy reference with the name fred public class ThingyDemo extends Object { public static void main( String[] args) { Thingy fred = null; Make fred refer to a new Thingy with initial value 5 fred = new Thingy(5); Set the value in the new Thingy to 10 fred.setThing( 10); Create an int called result and give it the number from the Thingy int result = fred.getThing(); Display the Thingy to the screenSystem.out.println( fred.toString()); }// end main() }// end ThingyDemo 10