FEN 2013-05-01KbP: Seminar 2/JML-Intro1 JML Introduktion Specifikation af en Personklasse.

Slides:



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

Classes And Objects II. Recall the LightSwitch Class class LightSwitch { boolean on = true; boolean isOn() { return on; } void switch() { on = !on; }
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.
Clonazione La clonazione... Ovvero: come costruire una copia (probabilmente che ritorni true su equals?)
1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
The Spec# programming system K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Lunch seminar, Praxis Bath, UK 6 Dec 2005 joint work with Mike Barnett,
Section 2.5 Single-Linked Lists. A linked list is useful for inserting and removing at arbitrary locations The ArrayList is limited because its add and.
Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.
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.
Intro to CS – Honors I More Objects and Methods GEORGIOS PORTOKALIDIS
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 {
Programming Methodology (1). Implementing Methods main.
Basic -2 Classes and Objects. Classes and Objects A class is a complex data TYPE An object is an instance of a class. Example: Class: Person Objects:
Phil Campbell London South Bank University Java 1 First Steps.
FEN IntroJava2006 AAU1 Nedarvning Specialisering/Generalisering Subklasse/Superklasse Statisk/Dynamisk type Polymorfi Interfaces.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
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.
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,
Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
Programming With Java ICS201 University Of Hail1 Chapter 13 Inner Classes.
The Singleton Pattern II Recursive Linked Structures.
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.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
Exercise 1 Suppose C is a class that implements interfaces I and J. Which of the following Requires a type cast? C c = ……? I i = …..? J j = …..? c =
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.
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.
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.
Singleton vs utility class  at first glance, the singleton pattern does not seem to offer any advantages to using a utility class  i.e., a utility class.
Reusable Classes.  Motivation: Write less code!
Ö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.
1 Design by Contract with JML CS 3331 Fall 2009 Gary T. Leavens and Yoonsik Cheon. Design by Contract with JML. Available from
Programming Progamz pls. Importance VERY IMPORTANT.
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!
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
FEN UCN T&B - PBA/CodeContract- Intro 1 Code Contract Introduction Specification of a Person Class.
1 OOP : main concepts Polymorphism. 2 OOP : main concepts  The main concepts:  In a superclass –public members Accessible anywhere program has a reference.
[ServiceContract] public interface IJokeOfTheDayService { [OperationContract] string GetJoke(int jokeStrength); }
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Inheritance in Java. Access Specifiers private keywordprivate keyword –Used for most instance variables –private variables and methods are accessible.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 7, Feb 6/7, 2013.
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Staples are our staple Building upon our solution.
יסודות מדעי המחשב – תרגול 6
Java Memory Management
Web Design & Development Lecture 9
Java Memory Management
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
Review Session.
Abstract Data Types and Java Classes
null, true, and false are also reserved.
CSC 113: Computer programming II
Creating Objects in a Few Simple Steps
Classes & Objects: Examples
CSE 1030: Implementing Non-Static Features
Code Animation Examples
Example with Static Variable
مظفر بگ محمدی دانشگاه ایلام
class PrintOnetoTen { public static void main(String args[]) {
Java Programming with Multiple Classes
Presentation transcript:

FEN KbP: Seminar 2/JML-Intro1 JML Introduktion Specifikation af en Personklasse

FEN KbP: Seminar 2/JML-Intro2 public class Person { private spec_public String name; private int weight; public invariant && weight >= also ensures \result != null; public String toString() { return "Person(\“” +name+"\","+weight+")"; } ensures \result == weight; public int getWeight() { return weight; } requires kgs >= requires weight + kgs >= ensures weight == \old(weight + public void addKgs(int kgs) { weight= weight+kgs; } requires n != null && ensures && weight == public Person(String n) { name= n; weight= 0; }

FEN KbP: Seminar 2/JML-Intro3 Adskild specifikation og implementation public interface PersonIF { public invariant getWeight() >= also ensures \result != null; public pure String toString(); ensures \result >= 0; public int getWeight(); requires kgs >= ensures getWeight() == (\old(getWeight()) + public void addKgs(int kgs); } Specifikation i interface

FEN KbP: Seminar 2/JML-Intro4 public class PersonImp implements PersonIF { private spec_public String name; private int weight; public invariant && weight >= also ensures \result != null; public pure String toString() { return "Person(\"“ +name+"\","+weight+")"; } also ensures \result == weight; public int getWeight() { return weight; } public void addKgs(int kgs) { weight= weight+kgs; } requires n != null && ensures && weight == public PersonImp(String n) { name= n; weight= 0; } public class PersonMain1 { public static void main(String[] args) { PersonIF p= new PersonImp("Kurt"); p.addKgs(99); System.out.println(p.toString()); } Implementation i class interface som statisk type class som dynamisk Implementation i class Constructor skal etablere invarianten.