What have we learned so far? u Week 1 Summary u There are things called classes that describe things we are interested in representing in software. u There.

Slides:



Advertisements
Similar presentations
Chapter 23 Organizing list implementations. This chapter discusses n The notion of an iterator. n The standard Java library interface Collection, and.
Advertisements

11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
A8 – Control Structures if, if-else, switch Control of flow in Java Any sort of complex program must have some ability to control flow.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Overview of Data Structures and Algorithms
HST 952 Computing for Biomedical Scientists Lecture 3.
CSC1016 Coursework Clarification Derek Mortimer March 2010.
1 Chapter 3 Arrays, Linked Lists, and Recursion. 2 Static vs. Dynamic Structures A static data structure has a fixed size This meaning is different than.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Flow of Control (1) : Logic Clark Savage Turner, J.D., Ph.D. Some lecture slides have been adapted from those developed.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
ECE122 L7: Conditional Statements February 20, 2007 ECE 122 Engineering Problem Solving with Java Lecture 7 Conditional Statements.
24-Jun-15 Pruning. 2 Exponential growth How many leaves are there in a complete binary tree of depth N? This is easy to demonstrate: Count “going left”
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
The Program Design Phases
Introduction SWE 619. Why Is Building Good Software Hard? Large software systems enormously complex  Millions of “moving parts” People expect software.
Truth Tables for Negation, Conjunction, and Disjunction.
Programming With Java ICS201 University Of Hail1 Chapter 12 UML and Patterns.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Intro to Discrete Structures
BUILDING COMPUTER CIRCUITS prepared by Burak Galip ASLAN September, 2006 BOOLEAN LOGIC AND GATES CONTROL CIRCUITS.
Boolean Algebra – the ‘Lingua Franca’ of the Digital World The goal of developing an automata is based on the following (loosely described) ‘ideal’: if.
Logic Gates & Boolean Algebra Chin-Sung Lin Eleanor Roosevelt High School.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
Invitation to Computer Science, Java Version, Second Edition.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Conditional Control Flow By Muhammad Ahsan Qadar SACS Programming Fundamentals Workshop 1.
Selection Control Structures Simple Program Design Third Edition A Step-by-Step Approach 4.
CSCI 1100/1202 January 28, The switch Statement The switch statement provides another means to decide which statement to execute next The switch.
1 Relational Expressions Relational expressions: –Expressions that compare operands –Sometimes called conditions –Evaluated to yield a result –Typically.
Java Software Solutions Lewis and Loftus Chapter 5 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. More Programming Constructs.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson Department of Computer and Information Science, IUPUI.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
Introduction to Java Java Translation Program Structure
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Chapter 7: Characters, Strings, and the StringBuilder.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
Chapter 3 Object Interaction.  To construct interesting applications it is not enough to build individual objects  Objects must be combined so they.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Objects – State u There are only two things we can do to an object u Inspect it’s state u Alter it’s state u This is a profound statement! u If you think.
ALGORITHMS.
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
1 b Boolean expressions b truth tables b conditional operator b switch statement b repetition statements: whilewhile do/whiledo/while forfor Lecture 3.
The Big Picture Chapter 3. A decision problem is simply a problem for which the answer is yes or no (True or False). A decision procedure answers a decision.
CS 106 Logic and Conditionals (Boolean Expressions)
Propositional and predicate logic
Relational Operator and Operations
Algorithms and Problem Solving
Debugging and Random Numbers
The order in which statements are executed is called the flow of control. Most of the time, a running program starts at the first programming statement,
Unit# 9: Computer Program Development
File Handling Programming Guides.
Chapter 3: Program Statements
Algorithms and Problem Solving
Introduction to Data Structure
Chap 7. Advanced Control Statements in Java
Introduction to Computer Science
Presentation transcript:

What have we learned so far? u Week 1 Summary u There are things called classes that describe things we are interested in representing in software. u There are things called objects that are realisations or instantiations or instances of classes. u Only objects can be manipulated. u The only things we can do to an object are u Inspect the state using a relational expression u Alter the state using assignment u Ensuring objects have the correct initial state is absolutely crucial. u Weeks 2 and 3 Summary u Inspection and alteration can be combined in three patterns (or programming constructs) – sequence, selection and iteration u For convenience a variety of selection and iteration mechanisms are provided. u Sophisticated computing solutions are created using objects that have a large number of simple operations, or methods. u Methods may require (parameter) data and may provide result (return) data u Methods can be categorised as functions or procedures. u Frequently occurring utility objects (e.g. strings) do not need to be built from scratch and are provided by Java with associated API (method headers) descriptions

Relational Expressions u Relational (or boolean) expressions are interesting because when evaluated they produce one of only two possible results. u To evaluate a relational expression Java simply tests the truth of the expression and reports on the outcome. u Evaluating the test involves deciding whether it is TRUE or FALSE; Yes or No. u Relational expressions are sometimes called conditions.

Relational Expressions u The following binary operators are defined for relational expressions ==equal<=Less than or equal !=not equal>=Greater than or equal >Greater than<Less than u Note double = is used for equality to avoid ambiguity with the assignment operator. u Relational operators are not type specific.

Relational Expressions u A simple relational expression involves one operator and two operands. u Examples of simple relational expressions 4 < 3 WeeklyPay > AverageIndustrialWage InterestRate <= 6.5 ApplicantsAge >= 18 LottoSlipNumber = = ChosenNumber CursorOffScreen = CursorPosition > ScreenWidth FoundIt = CurrentPageInBook = = PageToLookFor

Relational Expressions u The last two examples are important because they highlight the fact that, just like other expressions, the result of a relational expression can be assigned to a variable. u This practice can be a useful documentation aid because it allows us to name conditions thereby making the program a little easier to read.

Relational Expressions u More powerful relational expressions are possible using the Logical Operators AND and OR. u In effect, the logical operators are used toconnect two or more simple relational expressions thereby forming one composite relational expression. u Java uses && for specifying AND connections || for specifying OR connections

Relational Expressions u For example NumberOfPersons <= LiftCapacity && FloorSelected != CurrentFloor Age >= 18 && Age <= 65 EntryPoints >= CourseCutOff || Age >= 24 AccountType == Current || AccountType == Deposit u The Logical Operators have some very important behavioural characteristics which we need to remember. u These characteristics are often described pictorially by means of a TRUTH TABLE.

Truth Table for AND u The following truth table applies to the && operator RelExp1RelExp2Result TTT FTF TFF FFF u Notice that BOTH sub-expressions must be true for the result of the composite expression to be true.

Truth Table for AND u Truth Tables can easily be extended to describe composite expressions involving more than two sub-expressions. u NOTE, that no matter how many subexpressions are used the composite expression always produces a single result and this represents the result of the entire relational expression.

Truth Table for OR u The following truth table applies to the || operator RelExp1RelExp2Result TTT FTT TFT FFF u Notice that when ANY ONE of the sub- expressions is true the result of the composite expression is true.

Truth Table for OR u Again, the Truth Table can easily be extended to describe composite expressions involving more than two sub- expressions u NOTE, that no matter how many subexpressions are used the composite expression always produces a single result and this represents the result of the entire relational expression.

Scaling Up u When we create an algorithm to solve a particular problem we may find that the solution does not scale up for larger instances of the same problem. u For example, our solution for talking like a pirate is adequate (just about) for that particular instance of the problem but it would be completely inadequate, tedious and inefficient if the list had words or more!

Scaling Up u Ideally, we should try to develop solutions which lend themselves to modification for larger problems of the same type. u To create programs like this we need some more tools. u One of the major drawbacks of the pirate translator is that we had to include an if for each word so each one was unique. u Treating each one as unique makes adding new ones problematic.

Scaling Up u The pirate talker is an example of the type of situation we encounter quite frequently in programming environments. u Sometimes we would like to be able to treat a number of related items as a collection so that we would not have to explicitly reference each one. u At other times we would like to be able to treat them as separate and unique so that we can process them individually.

Scaling Up u Strings are an example of this type of requirement but they have limitations u We can only manipulate portions of the string u We cant change individual characters (we can of course inspect them but we cant alter them) u Alterations actually create new strings and discard the old ones String s = University ; String t = of Limerick ; s = s + t ;

Lists u A list is a collection of data items. u A list has three important aspects u The data in the list u The capacity of the list u The current usage of the capacity u What kind of things would we want to do to a list?

Lists u Add/Insert a new item u Remove/Delete an existing item u Modify an existing item u Show the list contents u Sorted in some order? u Find/Search the list for an item u Browse the list