javagently jg3e H:\ ProgTwo Programming II Lecture 7 A case study (class containing an array) and model diagrams. 02/02/2003 Dr Andy Brooks 1

Similar documents
CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CS 335 Lecture 02 Java Programming

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CS260 Intro to Java & Android 03.Java Language Basics

Object-Oriented Concepts

Full file at Chapter 2 - Inheritance and Exception Handling

Java Fundamentals (II)

Lab5. Wooseok Kim

Class, Variable, Constructor, Object, Method Questions

More on Objects in JAVA TM

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Lab 11. A sample of the class is:

Declarations and Access Control SCJP tips

1 Shyam sir JAVA Notes

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

CS 231 Data Structures and Algorithms, Fall 2016

Downloading Tweet Streams and Parsing

CS 161: Object Oriented Problem Solving

Lab5. Wooseok Kim

A foundation for programming. Classes and objects. Overview. Java primitive types. Primitive types Creating your own data types

Brief Summary of Java

Formatting Output & Enumerated Types & Wrapper Classes

Input from Files. Buffered Reader

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Lecture 2: Java & Javadoc

CHAPTER 7 OBJECTS AND CLASSES

COE318 Lecture Notes Week 9 (Week of Oct 29, 2012)

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Inheritance (Part 5) Odds and ends

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Getting Started in Java. Bill Pugh Dept. of Computer Science Univ. of Maryland, College Park

CS/ENGRD 2110 SPRING Lecture 5: Local vars; Inside-out rule; constructors

More on Exception Handling

CLASSES AND OBJECTS. Fundamentals of Computer Science I

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Vendor: Oracle. Exam Code: 1Z Exam Name: Java Certified Programmer. Version: Demo

Selected Questions from by Nageshwara Rao

CLASSES AND OBJECTS. Fundamentals of Computer Science I

CSCE3193: Programming Paradigms

CS 161: Object Oriented Problem Solving

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Lecture 17. For Array Class Shenanigans

Lecture Static Methods and Variables. Static Methods

Introduction to Computation and Problem Solving

Recitation: Loop Jul 7, 2008

COE318 Lecture Notes Week 8 (Oct 24, 2011)

Lecture Static Methods and Variables. Static Methods

CS 302: INTRODUCTION TO PROGRAMMING IN JAVA. Lecture 16

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

Another IS-A Relationship

Data Abstraction and Specification of ADTs

Java Input/Output. 11 April 2013 OSU CSE 1

Java and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1

Object Orientation Fourth Story. Bok, Jong Soon

The class Object. Lecture CS1122 Summer 2008

CS1083 Week 2: Arrays, ArrayList

Reading from URL. Intent - open URL get an input stream on the connection, and read from the input stream.

Timing for Interfaces and Abstract Classes

enum Types 1 1 The keyword enum is a shorthand for enumeration. Zheng-Liang Lu Java Programming 267 / 287

Array. Prepared By - Rifat Shahriyar

AP Computer Science A

CS 161: Object Oriented Problem Solving

Tirgul 1. Course Guidelines. Packages. Special requests. Inner classes. Inner classes - Example & Syntax

Review questions. Review questions, cont d. Class Definition. Methods. Class definition: methods. April 1,

ECE 122. Engineering Problem Solving with Java

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

CS 61B Discussion 5: Inheritance II Fall 2014

File Operations in Java. File handling in java enables to read data from and write data to files

Fundamentals of Object Oriented Programming

F I N A L E X A M I N A T I O N

Wrapper Classes double pi = new Double(3.14); 3 double pi = new Double("3.14"); 4... Zheng-Liang Lu Java Programming 290 / 321

Lecture 9: Arrays. Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp. Copyright (c) Pearson All rights reserved.

Lecture 02, Fall 2018 Friday September 7

Language Features. 1. The primitive types int, double, and boolean are part of the AP

CS 302 Week 9. Jim Williams

A final method is a method which cannot be overridden by subclasses. A class that is declared final cannot be inherited.

CHAPTER 7 OBJECTS AND CLASSES

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Java in 21 minutes. Hello world. hello world. exceptions. basic data types. constructors. classes & objects I/O. program structure.

Programming overview

Various useful classes

Full file at

School of Informatics, University of Edinburgh

Course Content. Objectives of Lecture 22 File Input/Output. Outline of Lecture 22. CMPUT 102: File Input/Output Dr. Osmar R.

FDK API Manual for Java. FDK API Manual for Java. June FN Pricing

16-Dec-10. Consider the following method:

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

BSc. (Hons.) Software Engineering. Examinations for / Semester 2

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

More on Exception Handling

Homework 3 Huffman Coding. Due Thursday October 11

Software and Programming 1

public static boolean isoutside(int min, int max, int value)

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

Interfaces (1/2) An interface forms a contract between the object and the outside world.

Nested Loops. A loop can be nested inside another loop.

Interfaces. An interface forms a contract between the object and the outside world.

CMSC 132: Object-Oriented Programming II

Transcription:

H:\ jg3e javagently ProgTwo Lab3 Laboratory Programming II Lecture 7 A case study (class containing an array) and model diagrams. 02/02/2003 Dr Andy Brooks 1

Scope The scope of an identifier is the region of a program source within which it represents a certain thing. This usually extends from the place where it is declared to the end of the smallest enclosing block. from FOLDOC 02/02/2003 Dr Andy Brooks 2

Accessibility control Modifier Class Member no modifier public private protected abstract final static Accessible only within its package. Accessible anywhere its package is. n/a n/a May not be instantiated. May not be sub-classed. A top-level class not an inner one. Accessible only within its package. Accessible anywhere its class is. Accessible only within its own class. Accessible within its package and its subclasses A method is not implemented here but in a subclass. A value may not be changed, a method not overridden. Class member accessed through its class name. 02/02/2003 Dr Andy Brooks JavaGently page 325 3

A clear understanding of accessibility control is required if programs in one project folder (package) are to make use of classes in another folder (package). import java.io.*; import javagently.*; class Experiments { int x; int y; package javagently; import java.io.*; import java.util.*; import java.text.*; public class Stream { 02/02/2003 Dr Andy Brooks 4

A reminder of modelling notation. Classid Classid Classid objectid variables methods objectid Classid - variableprivate -methodprivate +methodpublic packageid Classes variables methods objectid packageid java.io.* Hashtable h :CurioStore1 Key Value Classid mugs mugs CurioStore1() price = 6 write() arrayid[ ] 0 1 null null explanations 2 null 02/02/2003 Dr Andy Brooks 5

class IntArray { private int A []; IntArray (int n) { A = new int [n]; int get (int i) { return A [i]; void set (int i, int x) { A [i] = x; case study: class containing an array JavaGently page 210 Note the scope of A. // Object class has a tostring() method - example here of method overriding public String tostring () { String s = ""; for (int i = 0 ; i < A.length ; i++) { s += " " + A [i]; return s; 02/02/2003 Dr Andy Brooks 6 arrays are always indexed starting at 0. length is a property not a method.

import java.lang.*; //done automatically and includes Math class import java.io.*; class ArrayTest { A test program using ArrayTest () throws IOException { IntArray marks = new IntArray (5); class IntArray int m; for (int i = 0 ; i < 5 ; i++) { m = (int) (Math.random () * 100); marks.set (i, m); System.out.println (marks); public static void main (String args []) throws IOException { new ArrayTest (); Do we need throws IOException here? Do we need import java.io.* here? 02/02/2003 Dr Andy Brooks 7

Modelling notation Users of the notation may provide as much or as little detail and timewise detail as they wish Details may include: variables (attributes) and methods parameter lists accessibility control explanation notes for methods and statements classes and objects Under test, assignment, or examination conditions, the level of detail to be provided will be made clear. 02/02/2003 Dr Andy Brooks 8

IntArray Create the private array A - int A [] IntArray(int) int get (int) set(int,int) + String tostring() Return the value at the subscript given Set the value at the the subscript given Return a string representation of the private Array A - private + public 02/02/2003 Dr Andy Brooks 9

ArrayTest :ArrayTest ArrayTest() main(string args[]) ArrayTest() IntArray marks = new IntArray[5] - int A [] IntArray IntArray(int) int get (int) set(int,int) + String tostring() - int A [] marks IntArray(int) int get (int) set(int,int) + String tostring() 0 1 2 3 Model diagram at a particular moment in time. Nothing is set into the array. 4 02/02/2003 Dr Andy Brooks 10

Curiostore3() // Declare object variables relevant to all methods Display display = new Display ("Polelo Curio Store"); Curio mugs, tshirts, carvings; boolean open; CurioStore3() void report() void stockthestore() void openthestore() void sellcurios() void available() 02/02/2003 Dr Andy Brooks 11

Curiostore3 Display display Curio mugs,tshirts,carvings boolean open main(string [ ] args) CurioStore3() void report() void stockthestore() void openthestore() void sellcurios() void available() Note the absence of accessibility modifiers. 02/02/2003 Dr Andy Brooks 12