CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Similar documents
CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Where do objects come from? Good question!

Arrays, Part 3: Multidimensional arrays

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

Designing Classes. Where do objects come from? Where do objects come from? Example: Account datatype. Dr. Papalaskari 1

Designing Classes part 2

Java Bootcamp - Villanova University. CSC 2014 Java Bootcamp. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Designing Classes. Where do objects come from? Where do objects come from? Example: Account datatype. Dr. Papalaskari 1

CSC 1051 Data Structures and Algorithms I

Arrays - Review. Two-Dimensional Arrays. Arrays, Part 2. Dr. Papalaskari 1. CSC 1051 Data Structures and Algorithms I

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

ECE 122. Engineering Problem Solving with Java

Chapter. We've been using predefined classes. Now we will learn to write our own classes to define objects

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name:

Selection Statements and operators

Introduction to Arrays

CSC 1051 Algorithms and Data Structures I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java

Selection Statements and operators

CSC 1051 Villanova University. CSC 1051 Data Structures and Algorithms I. Course website:

CSC 1051 Algorithms and Data Structures I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name: Question Value Score

Anatomy of a Class Encapsulation Anatomy of a Method

Method OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters

CSC 1051 Data Structures and Algorithms I

Happy Cinco de Mayo!!!!

Selection and Repetition Revisited

Basics of Java Programming variables, assignment, and input

Algorithms in everyday life. Algorithms. Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs

Algorithms in everyday life. Algorithms. Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs

Happy Cinco de Mayo!!!!

Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs

Arrays - Review. Arrays as Parameters. Arrays as Parameters. Arrays and File Input. Dr. Papalaskari 1. CSC 1051 Data Structures and Algorithms I

Arrays and File Input

Selection and Repetition Revisited

Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs

Control flow, conditionals, boolean expressions, block statements, nested statements. Course website:

Algorithms and Conditionals

Arrays and File Input

Improved algorithm. Java code. Control flow and conditionals CSC 1051 Villanova University. Dr Papalaskari 1. Java Programè Algorithm

Java code. Updated program. Control flow and conditionals CSC 1051 Villanova University. Dr Papalaskari 1. Java Programè Algorithm. Improved algorithm

Java I/O and Control Structures

Anatomy of a Method. HW3 is due Today. September 15, Midterm 1. Quick review of last lecture. Encapsulation. Encapsulation

Selection and Repetition

Iterators and File Input

writing classes objectives chapter

Conditional Statements

Java I/O and Control Structures Algorithms in everyday life

Packages & Random and Math Classes

Chapter 7. Arrays are objects that help us organize large amounts of information

Java Basic Introduction, Classes and Objects SEEM

CSC 2014 Java Bootcamp. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

7.3 Arrays of Strings (Objects) 7.3 Arrays of Strings (Objects) 7.3 Tunes.java. 7.3 Arrays of Objects 9/11/13. ! A UML diagram for the Tunes program

Lecture 3: Variables and assignment

Java Basic Introduction, Classes and Objects SEEM

EXAM Computer Science 1 Part 1

Selection and Repetition

Introduction to Programming Using Java (98-388)

H212 Introduction to Software Systems Honors

COMP 202. Programming With Arrays

2: Basics of Java Programming

Arrays - Review. Initializer Lists. The for-each Loop. Arrays, Part 2. Dr. Papalaskari 1. CSC 1051 Data Structures and Algorithms I

Final Exam CS 152, Computer Programming Fundamentals December 5, 2014

Final Exam. COMP Summer I June 26, points

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2014

Using Classes and Objects

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

Classes and Methods: Classes

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

Computer Science II (20082) Week 1: Review and Inheritance

Arrays in Java Multi-dimensional Arrays

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Chap. 3. Creating Objects The String class Java Class Library (Packages) Math.random() Reading for this Lecture: L&L,

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

COMP 202. More on OO. CONTENTS: static revisited this reference class dependencies method parameters variable scope method overloading

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name:

Using Classes and Objects

ENGR 2710U Midterm Exam UOIT SOLUTION SHEET

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name: KEY. Question Value Score

Inheritance. Quick Review of Last Lecture. November 12, Passing Arguments. Passing Arguments. Variable Assignment Revisited

ANSWER KEY First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

Programming with Java

Chapter 4 Writing Classes

Data Representation and Applets

I/O Streams. program. Standard I/O. File I/O: Setting up streams from files. program. File I/O and Exceptions. Dr. Papalaskari 1

I/O Streams. program. Standard I/O. File I/O: Setting up streams from files. program. File I/O and Exceptions. Dr. Papalaskari 1

Recitation: Loop Jul 7, 2008

Graphical User Interfaces

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

Using Classes and Objects

Transcription:

Last Class CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this presentation are adapted from the slides accompanying Java Software Solutions by Lewis & Loftus

We learned Fundamental algorithms finding max/min, average repeated interactive input processing lists processing 2D tables of data file management creating and handling exceptions Fundamental data structures Classes that aggregate information (eg: Account, Shoe, Person) Strings Arrays The basics of Java

We studied many ways of controlling flow through a program while Loop do Loop condition evaluated true statement int count = 0; while (count < 5) System.out.println (count); count++; } false true statement condition evaluated false int count = 0; do System.out.println (count); count++; } while (count < 5);

We studied ways to structure data Declaration: double[] scores Instantiation: = new double[10]; The entire array has a single name index array element scores[2] scores Initialization: scores[0] = 7.9; scores[1] = 8.7; scores[2] = 9.4; scores[3] = 8.2; scores[4] = 6.7; scores[5] = 9.8; scores[6] = 8.7; scores[7] = 8.1; scores[8] = 7.4; scores[9] = 9.1; 0 1 2 3 4 5 6 7 8 9 7.9 8.7 9.4 8.2 6.7 9.8 8.7 8.1 7.4 9.1 This array holds 10 values of type double that are indexed from 0 to 9 The size of the array is given by: scores.length = 10

We wrote classes that work together //******************************************************************** // Transactions.java Author: MA Papalaskari // (based on Lewis/Loftus example) // Demonstrates the creation and use of multiple Account objects. //******************************************************************** String name; public class Transactions // ******************************************************************** Constructor //----------------------------------------------------------------- // Account.java Author: Lewis/Loftus // Creates some bank accounts and requests various services. // Simplified code by MA Papalaskari //----------------------------------------------------------------- deposit() // Represents a bank account with methods deposit public and withdraw. static void main (String[] args) // ******************************************************************** withdraw() Account acct1 = new Account ("Ted Murphy", 72354, 102.56); import java.text.numberformat; Account acct2 = new Account ("Jane Smith", 69713, 40.00); getbalance() Account acct3 = new Transactions Account ("Edward Demsey", 93757, 759.32); public class Account System.out.println (acct1); int acctnumber; tostring() System.out.println (acct2); double balance; System.out.println (acct3); Client String name; acct1.deposit (25.85); //--------------------------------------------------------------- Account acct1.withdraw (60, 2.50); -- // Sets up the account by defining its owner's name, System.out.println account (); // number, and initial balance. System.out.println (acct1); //--------------------------------------------------------------- Datatype System.out.println (acct2); -- System.out.println (acct3); public Account (String x, int y, double z) } } name = x; acctnumber = y; balance = z; int acctnumber; double balance; }

We learned about graphics and JavaFX red=116 green=86 blue=142 y = 8 Color ( 01110100, 01010110, 10001110 ) x = 11 fff

We made SNOW DAYS!

We ran a lot of programs! //******************************************************************** Output // TwoDArray.java Author: Lewis/Loftus // 0 // Demonstrates 1 2 the use 3 of a 4 two-dimensional 5 array. 6 7 8 9 10 //******************************************************************** 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 public 31 class 32 TwoDArray 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 //----------------------------------------------------------------- // Creates a 2D array of integers, fills it with increasing // integer values, then prints them out. //----------------------------------------------------------------- public static void main (String[] args) int[][] table = new int[5][10]; // Load the table with values for (int row=0; row < table.length; row++) for (int col=0; col < table[row].length; col++) table[row][col] = row * 10 + col; // Print the table for (int row=0; row < table.length; row++) for (int col=0; col < table[row].length; col++) System.out.print (table[row][col] + "\t"); System.out.println();

The basics of Java style comments identifiers variables constants assignment statement primitive types objects classes packages methods assignment arithmetic ops boolean ops casting algorithms comparison aliases formatting output instance variables visibility scope static return statement if-else while for do/while 7-11 GUI classes Graphics JavaFX file input/outp arrays arrays of objects 2D arrays from the Library Strings Scanner Random Math GUI classes etc etc etc

So now we understand What an algorithm is How data can be represented and used The basics of Java What programming is... What object-orientation is... A little about computer architecture A way of thinking If we like computer science... or not

Final Exam Similar to quizzes and midterm.. but longer Same material: algorithms writing and using classes tracing code coding: proper naming, indentation but commenting not needed statements code fragments methods classes Partial credit available Be legible Check your work (eg, double check that you have the right type) Don t get stuck Don t write more than you are asked to write