Lab 1 Logbook ADT. OVERVIEW A monthly logbook consists of a set of entries, one for each day of the month.

Slides:



Advertisements
Similar presentations
Queues Printer queues Several jobs submitted to printer Jobs form a queue Jobs processed in same order as they were received.
Advertisements

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.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Introduction to Programming
Linear Lists – Array Representation
Lab 8 Ordered list. OVERVIEW In an ordered list the elements are maintained in ascending (or descending) order based on the data contained in the list.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
Written by: Dr. JJ Shepherd
Arrays part 2 Applications & such. Returning an array from a method A method can return an array, just like it can return any other kind of variable;
1 CSCD 326 Data Structures I Stacks. 2 Data Type Stack Most basic property: last item in (most recently inserted) is first item out LIFO - last in first.
1 Dynamic Arrays  Why Dynamic Arrays?  A Dynamic Array Implementation  The Vector Class  Program Example  Array Versus Vector.
18 File handling1June File handling CE : Fundamental Programming Techniques.
CS102--Object Oriented Programming Lecture 6: – The Arrays class – Multi-dimensional arrays Copyright © 2008 Xiaoyan Li.
Session 4 Command-Line Arguments, Strings, and Files.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/30/2012 and 10/31/2012 -Code PrintCalendar.
Io package as Java’s basic I/O system continue’d.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
CM0551 Exam Prep. What are an algorithm’s time and space complexity? (2 marks) Answer: The growth rate of the algorithm’s time requirement and the computer.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
6 Stack ADTs  Stack concepts  Stack applications  Stack ADTs: requirements, contracts  Implementations of stacks: using arrays and linked-lists  Stacks.
Stack. Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
More arrays Primitive vs. reference parameters. Arrays as parameters to functions.
Java Arrays …………. Java Arrays …………. * arrays are objects in Java * arrays are objects in Java * an array variable is a reference * an array variable is.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
CSC 212 Stacks & Queues. Announcement Many programs not compiled before submission  Several could not be compiled  Several others not tested with javadoc.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
CSC 205 Programming II Lecture 18 The Eight Queens Problem.
30 May Stacks (5.1) CSE 2011 Winter Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
1 The Stack Class Final Review Fall 2005 CS 101 Aaron Bloomfield.
Java 1.5 The New Java Mike Orsega Central Carolina CC.
Object-Oriented Programming Simple Stack Implementation.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
HashCode() 1  if you override equals() you must override hashCode()  otherwise, the hashed containers won't work properly  recall that we did not override.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Question 1a) What is printed by the following Java program? int s; int r; int i; int [] x = {4, 8, 2, -9, 6}; s = 1; r = 0; i = x.length - 1; while (i.
Lab 2 Point List. OVERVIEW In this laboratory, you explore lists in which each element is a two-dimensional point or (x,y) pair. We refer to this type.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
Lab 6 Stack ADT. OVERVIEW The stack is one example of a constrained linear data structure. In a stack, the elements are ordered from most recently added.
Chapter - 11 Introduction to File and Streams This chapter includes -  Defining a File  Testing and Checking File Objects  Accessing File Objects.
Sit-In Lab 2 - OOP Restaurant.  Manage a restaurant and perform these types of queries: Assign a favorite table to a specific group Assign the lexicographically-smallest.
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
Written by: Dr. JJ Shepherd
Files Review For output to a file: –FileOutputStream variable initialized to filename (String) and append/not append (boolean) –PrintWriter variable initialized.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade Know: loops, switch/case Files Input failure (e.g. scan.hasNextInt())
1 The copy constructor in the BankAccounts class. Two alternatives here: /** copy constructor */ public BankAccounts(BankAccounts L){ theAccounts = L.theAccounts.clone();
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Section 2.2 The StringLog ADT Specification. 2.2 The StringLog ADT Specification The primary responsibility of the StringLog ADT is to remember all the.
A 2-D Array is a structure that storage space both vertically and horizontally. Thus, the array has both rows and columns. 2-D Arrays are used to create.
CSC111 Quick Revision.
Control Structures.
Computer Programming Methodology File Input
Accessing Files in Java
Chapter 5: Control Structures II
نوع داده هاي انتزاعي Abstract Data Types
An Introduction to Java – Part I, language basics
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade
COMPUTER 2430 Object Oriented Programming and Data Structures I
Code Refresher Test #1 Topics:
COMPUTER 2430 Object Oriented Programming and Data Structures I
Question 1a) What is printed by the following Java program? int s;
Objects with ArrayLists as Attributes
CSC 205 – Java Programming II
A type is a collection of values
Presentation transcript:

Lab 1 Logbook ADT

OVERVIEW A monthly logbook consists of a set of entries, one for each day of the month.

OVERVIEW This is an example of a logbook for February:

Elements A set of integer values for a logbook month and its associated calendar.

Structure Each integer value is the logbook entry for a given day of the month. The number of logbook entries varies depending on the month for which data is being recorded.

Constructor Logbook ( int month, int year ) Precondition: Month is a valid calendar month between 1 and 12 inclusive. Postcondition: Constructor. Creates an empty logbook for the specified month that is, a logbook in which all the entries are zero.

Methods void putEntry ( int day, int value ) int getEntry ( int day ) int month ( ) int year ( ) int daysInMonth ( )

class Logbook { // Data members private int logMonth, // Logbook month logYear; // Logbook year private int[] entry = new int[31]; // Array of Logbook entries private GregorianCalendar logCalendar; // JavaÕs built-in Calendar class // Constructor public Logbook ( int month, int year ) // Create a logbook { } // Logbook marking operations/methods public void putEntry ( int day, int value ) // Store entry for day { } public int getEntry ( int day ) // Return entry for day { } // General operations/methods public int month ( ) // Return the month { } public int year ( ) // Return the year { } public int daysInMonth ( ) // Number of days in month { } } // class Logbook

import java.io.*; // For reading (keyboard) & writing (screen) import java.util.*; // For GregorianCalendar class class Logbook { // Data members private int logMonth, // Logbook month logYear; // Logbook year private int[] entry = new int[31]; // Array of Logbook entries private GregorianCalendar logCalendar; // JavaÕs built-in Calendar class // Constructor public Logbook ( int month, int year ) // Create a logbook { } // Logbook marking operations/methods public void putEntry ( int day, int value ) // Store entry for day { } public int getEntry ( int day ) // Return entry for day { } // General operations/methods public int month ( ) // Return the month { } public int year ( ) // Return the year { } public int daysInMonth ( ) // Number of days in month { } // Facilitator (helper) method private boolean leapYear ( ) // check if it is a Leap year? { if( ((logYear % 4 == 0) && (logYear % 100 != 0)) || (logYear % 400 == 0) ) return true; else return false; } } // class Logbook Complete necessary code

Implementation of the sample Coffee ADT for testing the Logbook ADT import java.io.*; // For reading (keyboard) & writing (screen) class Coffee { // Records coffee intake for January public static void main ( String args[] ) throws IOException { int day; // Day loop counter // Coffee intake for January 2002 Logbook coffee = new Logbook(1, 2002); // Record entries for the 1st and 15th of January 2002 coffee.putEntry(1, 5); coffee.putEntry(15, 2); // Output the logbook entries. System.out.println("Month/Year : " + coffee.month() + "/" + coffee.year()); for ( day = 1 ; day <= coffee.daysInMonth() ; day++ ) System.out.println(day + " : " + coffee.getEntry(day)); } // main( ) } // class Coffee Test logbook class with this coffee class

You should.. Send me two java files – Logbook class – Coffee class It should be complete and working well Submit by before your lab time