Lab 2. Prepare: 1.Create a folder named lab2 inside the workspace. 2.Download RecordDB.java and Record.java from the lab document. 3.Change the file name.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Lists: An internal look
The ArrayList Class and the enum Keyword
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.
Operator overloading redefine the operations of operators
Container Classes A container class is a data type that is capable of holding a collection of items. In C++, container classes can be implemented as.
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14: More About Classes.
Copyright © 2012 Pearson Education, Inc. Chapter 14: More About Classes.
Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
EC-241 Object-Oriented Programming
A C LOSER L OOK AT C LASSES 1. A SSIGNING O BJECTS One object can be assigned to another provided that both objects are of the same type. It is not sufficient.
An Array-Based Implementation of the ADT List public class ListArrayBased implements ListInterface { private static final int MAX_LIST = 50; private Object.
C++ data types. Structs vs. Classes C++ Classes.
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
Review of C++ Programming Part II Sheng-Fang Huang.
Constructors and Other Tools Version 1.0 Topics Constructors & Destructors Composition const Parameter Modifier const objects const functions In-line.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
1 Working with MS SQL Server Textbook Chapter 14.
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!
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
Dynamically Allocated Arrays December 4, Skip the Rest of this PowerPoint.
VG101 RECITATION 1 By TAs. CONTENTS Intro to SAKAI Intro to APG Intro to Online Quiz System Installation of VS2005 and possible resources Some common.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
Documentation javadoc. Documentation not a programmer's first love lives in a separate file somewhere usually a deliverable on the schedule often not.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
C arrays are limited: -they are represented by pointers (which may or may not be valid); -Indexes not checked (which means you can overrun your array);
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
1 ENGI 2420 Structured Programming (Lab Tutorial 7) Memorial University of Newfoundland.
Tool Install How to download & install Java 6 & Eclipse updated version based on Dr. G. L. Ray’s slides.
Classes and Objects CS177 Rec 10. Announcements Project 4 is posted ◦ Milestone due on Nov. 12. ◦ Final submission due on Nov. 19. Exam 2 on Nov. 4 ◦
ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.
Container Classes  A container class is a data type that is capable of holding a collection of items.  In C++, container classes can be implemented as.
Chapter 4 Generic Vector Class. Agenda A systemic problem with Vector of Object – Several approaches at a solution – Generic structures Converting classes.
Programming II Array of objects. this Using the this Pointer this Objects use the this pointer implicitly or explicitly. – this is – this is used implicitly.
Separate Compilation Bryce Boe 2013/10/09 CS24, Fall 2013.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
1 ENGI 2420 Structured Programming (Lab Tutorial 7) Memorial University of Newfoundland.
BIL528 – Bilgisayar Programlama II Methods 1. Contents Methods 2.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
There Will Be Times That You Come To Class & I Dump A Whole Bunch Of New Stuff On You & You Leave Confused! TODAY MAY BE ONE OF THOSE DAYS! You.
Object Oriented Programming I ( ) Dr. Adel hamdan Part 03 (Week 4) Dr. Adel Hamdan Date Created: 7/10/2011.
1 Low Level ADO.NET Operations II Microsoft Visual C# 2008 Step by Step Chapter 25.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
CSE 373 Spring 2016 HW 3 BST: Keyword Search due Friday April 22.
Today Encapsulation. Build a fully encapsulated Halloween class, going from Halloween1 to Halloween6 (eventually!): –The final version will have overloaded.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
An Array-Based Implementation of the ADT List
22C:21 Problem 2 (Set 1) Solution outline.
CVS : Add new file Team -6 October 28, 2004.
USING ECLIPSE TO CREATE HELLO WORLD
HKCT Java OOP Unit 02 Object Oriented Programming in Java Unit 02 Methods, Classes, and Objects 1.
Classes & Objects: Examples
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
February , 2009 CSE 113 B.
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
Lab – 2018/04/12 implement getTotalCount to return how many ‘nMatrix’s are allocated(exist) (modify constructor and destructor, use static variable and.
C++ data types.
Chapter 11 Classes.
Presentation transcript:

Lab 2

Prepare: 1.Create a folder named lab2 inside the workspace. 2.Download RecordDB.java and Record.java from the lab document. 3.Change the file name RecordDB.java to DynamicRecordDB.java. 4.Launch Eclipse and create a new project named lab2. 5.Open DynamicRecordDB.java. 6. Subtitute "RecordDB" in DynamicRecordDB.java by "DynamicRecordDB" everywhere.

1. Change the type of maxRecords from static int to int. Change the default value of maxRecords from 200 to Change the declaration of recordList. private static int maxRecords = 200; private int numRecords = 0; private Record recordList[] = new Record[maxRecords]; private int maxRecords = 1; private int numRecords = 0; private Record recordList[];

3. Add two constructors: DynamicRecordDB() and DynamicRecordDB( int n ). // The default constructor; allocates an array of size 1. DynamicRecordDB( ) { recordList = new Record[ maxRecords ]; } // Allocates an array of size n. // If the user knows the maximum size of the employee // database, they might prefer to use this constructor DynamicRecordDB( int n ) { //update maxRecords to n maxRecords = n; //Create an array of size=maxRecords. recordList = new Record[ maxRecords ]; }

4. Modify insert method to double the size of recordList when overflow may occur. public void insert ( Record rec ) { // Check for overflow if ( numRecords == maxRecords – 1 ) { return;// Increase the size of the array maybe } …… Do nothing and return if overflow may occur. old version

public void insert (Record rec) { // Double the size of the array, if overflow may occur. if (numRecords == maxRecords-1) { //create of a new array of the double size Record[ ] tempRecord = new Record[ 2 * maxRecords ]; // Copy the contents of recordList to tempRecord for( int i = 0; i < maxRecords; i++) tempRecord[ i ] = recordList[ i ]; // Make recordList point to tempRecord recordList = tempRecord; //Change maxRecords to the new value maxRecords = 2 * maxRecords; //return; } ……

Time of insertion operations

Average time of each insertion operation