public class Account { private int id; private static int nextaccountid = 0; private String name; private double balance;

Similar documents
Chapter 15 Chapter 11

CSE115 Introduction to Computer Science I Coding Exercise #7 Retrospective Fall 2017

Administrivia. CPSC Winter 2008 Term 1. Department of Computer Science Undergraduate Events

Practice problem on defining and using Class types. Part 4.

Encapsulation. Mason Vail Boise State University Computer Science

Handout 8 Classes and Objects Continued: Static Variables and Constants.

Programming a Bank Database. We ll store the information in two tables: INTEGER DECIMAL(10, 2)

Lab4 Task2- Solution LAB ASSIGNMENT:

Review. these are the instance variables. these are parameters to the methods

Object oriented programming

Outline CSE 142. Specification vs Implementation - Review. CSE142 Wi03 F-1. Instance Variables

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

$ % $ % BankAccount. public class BankAccount {... private??? balance; } "commands, transformers, mutators! "abstract state! "queries, accessors!

Storing Data in Objects

Implementing Classes

STUDENT LESSON A5 Designing and Using Classes

Implementing Classes (P1 2006/2007)

BankAccount account1 = new BankAccount(...);,this

Agenda: Notes on Chapter 3. Create a class with constructors and methods.

Intro to Computer Science 2. Inheritance

Data types. CISC 1600/1610 Computer Science I. Class dog. Introducing: classes. Class syntax declaration. Class syntax function definitions 12/2/2015

Practical Session 2 Correction Don't forget to put the InputValue.java file in each project

Chapter Goals. Chapter 9 Inheritance. Inheritance Hierarchies. Inheritance Hierarchies. Set of classes can form an inheritance hierarchy

COMP-202 Unit 8: Defining Your Own Classes. CONTENTS: Class Definitions Attributes Methods and Constructors Access Modifiers and Encapsulation

SWC test question #01. Using objects part I

Eduardo M. Breijo Baullosa May 2, Assignment 17. Report

C C C C++ 2 ( ) C C++ 4 C C

ICOM 4015: Advanced Programming

Practice Midterm Examination

Assertions, pre/postconditions

ATM Use Cases. ID: CIS Title: Check Balance Description: Customer aims to know the balance in his/her account

CHAPTER 10 INHERITANCE

CS 106X, Lecture 14 Classes and Pointers

Inheritance Advanced Programming ICOM 4015 Lecture 11 Reading: Java Concepts Chapter 13

Inheritance (P1 2006/2007)

Quarter 1 Practice Exam

Sample Solution Assignment 5. Question R3.1

Arrays and Array Lists

Chapter 8. Arrays and Array Lists. Chapter Goals. Chapter Goals. Arrays. Arrays. Arrays

Data types. CISC 1600/1610 Computer Science I. Class dog. Introducing: classes. Class syntax declaration. Class syntax function definitions 4/19/2015

CSCI-1200 Computer Science II Fall 2006 Lecture 23 C++ Inheritance and Polymorphism

Using the Xcode Debugger

Chapter 10 Inheritance. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

Date: AIM. Write a Java program to demo simple inheritance PROCEDURE

2/9/2012. Chapter Three: Implementing Classes. Chapter Goals

9/2/2011. Chapter Goals

Administrivia. IBM Info Session Date: Wed,, Jan 13 Time: 5:30 7 pm Location: Wesbrook 100

BloomBank Financial Software Design

EXAMINATIONS 2012 END-OF-YEAR SWEN222. Software Design. Question Topic Marks 1. Design Quality Design Patterns Design by Contract 12

CSCI-1200 Data Structures Fall 2017 Lecture 25 C++ Inheritance and Polymorphism

CSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes

Building Your Own Classes

Location: Planet Laser Interview Skills Workshop

Class 09 Slides: Polymorphism Preconditions. Table of Contents. Postconditions

Chapter Seven: Arrays and Array Lists. Chapter Goals

Handout 9 OO Inheritance.

Lecture 07: Object Encapsulation & References AITI Nigeria Summer 2012 University of Lagos.

CSIS 10A Practice Final Exam Name:

Outline for Today CSE 142. CSE142 Wi03 G-1. withdraw Method for BankAccount. Class Invariants

COMPSCI 230 Threading Week8. Figure 1 Thread status diagram [

Chapter Goals. T To understand the concept of regression testing. Chapter 6 Arrays and Array Lists. Arrays Array: Sequence of values of the same type

Programming Abstractions

CSE 142, Spring 2010 Final Exam Wednesday, June 9, Name: Student ID #: Rules:

6.096 Introduction to C++

ECE 122. Engineering Problem Solving with Java

COSC This week. Will Learn

Software Engineering: Design & Construction

Exercises 1. class member { int membernum = 25; float memberpay; public void Input(cin >> membernum >> memberpay); void Output; }

CMSC 202. Exceptions

CS1020 Data Structures and Algorithms I Lecture Note #8. Exceptions Handling exceptional events

Assertions. Assertions - Example

Name: Checked: Objectives: Practice creating classes and methods, and using them in your programs.

Name: Checked: Objectives: Practice creating classes and methods, and using them in your programs.

Implementation. (Mapping to Java) Jörg Kienzle & Alfred Strohmeier. COMP-533 Implementation

Introduction to Inheritance

Instance Method Development Demo

Developed By Strawberry

CSCI-1200 Data Structures Spring 2016 Lecture 23 C++ Exceptions, Inheritance, and Polymorphism

IT 313 Advanced Application Development

Classes and Methods: Classes

CSC 175 Intermediate Programming

Integrating verification in programming languages

Chapter 5: Arrays. Chapter 5. Arrays. Java Programming FROM THE BEGINNING. Copyright 2000 W. W. Norton & Company. All rights reserved.

Chapter Goals. Chapter 5 - Iteration. Calculating the Growth of an Investment

Mutating Object State and Implementing Equality

1/9/2015. Intro to CS: Java Review Assignment Due Dates Chapter 7 7.1: while Loops 7.2: for Loops Ch7 Work Time. Chapter 7 Iteration WHILE LOOPS

WEEK 13 EXAMPLES MONDAY SECTION 2. Author class. public class Author { private static int ID=0; private String AuthorName;

Five EASY Steps to Switch to

FDSc in ICT. Building a Program in C#

Testooj user s manual October 25, 2007

class declaration Designing Classes part 2 Getting to know classes so far Review Next: 3/18/13 Driver classes:

Catching Defects: Design or Implementation Phase? Design-by-Contract (Dbc) Test-Driven Development (TDD) Motivation of this Course

CSE 143 Lecture 3. More ArrayList; object-oriented programming. reading: 10.1;

Inheritance & Abstract Classes Fall 2018 Margaret Reid-Miller

CSE 331. Programming by contract: pre/post conditions; Javadoc

More Shared Memory Programming

CSE 413 Winter 2001 Midterm Exam

Final Exam Time: Friday, August 12th, 12:15pm - 3:15pm Final Exam Location: Split by last name

What will this print?

What This Course Is About Design-by-Contract (DbC)

Transcription:

public class Account { private int id; private static int nextaccountid = 0; private String name; private double balance; public double deposit(double amount) { public double withdraw(double amount) {

* @invariant getid()is unique and set when account is created * @invariant getname()is set when account is created * @invariant the values of getid() and getname() never change * @invariant public class Account { private int id;

Chapter 15 Chapter 11

/** * Deposit money into the account * @param amount The amount to be deposited * * @pre true * @post IF amount >= 0 * THEN getbalance() = @pre.getbalance() + amount * ELSE getbalance() = @pre.getbalance() * @throws IllegalValueException if amount is negative */ public void deposit(double amount) throws IllegalValueException { if (amount < 0) throw new IllegalValueException("Error: Neg. amount"); balance = balance + amount; }

IllegalValueException IllegalValueException

IllegalValueException

/** * A simple bank account for which the balance can never be * less than zero * * @invariant getbalance() >= 0 * @invariant getid() is unique and set when account is created * @invariant getname() is set when account is created * @invariant the values of getid() and getname() never change */ public class Account { private int id; private static int nextaccountid = 0; private String name; private double balance;

/** * Initializes an account * @param accountname Customer name for account * @param initialbalance Initial balance deposited in account * * @pre true * @post getname() = accountname * @post getid() = a new number not returned by other accounts * @post (initialbalance>=0 AND getbalance() = initialbalance) * OR getbalance() = 0 * */ public Account(String accountname, double initialbalance) { id = nextaccountid++; name = accountname; if (initialbalance >= 0) balance = initialbalance; else balance = 0; } /** * Accessor method to return the account id * @pre true * @return the account id */ public int getid() { return id; } /** * Accessor method to return the customer name * @pre true * @return he customer name */ public String getname() { return name; } /** * Deposit money into the account * @param amount The amount to be deposited * * @pre amount >= 0 * @post getbalance() = @pre.getbalance() + amount * @return The current balance of the account */ public double deposit(double amount) { assert amount >= 0; balance = balance + amount; return balance; } /** * Withdraw money from the account * @param amount The amount to be withdrawn * * @pre amount >= 0 * @post IF (@pre.getbalance()-amount >= 0 ) * THEN getbalance() = @pre.getbalance() - amount * ELSE getbalance() = @pre.getbalance() * @return The current balance of the account */ public double withdraw(double amount) { assert amount >= 0; if (balance - amount >= 0) balance = balance - amount; return balance; }

/** * Returns the string representation of an account * * @pre true * @return the account represented as a string */ public String tostring() { return "[ id = " + id + ", name = " + name + ", balance = " + balance + "]"; } }