Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.

Slides:



Advertisements
Similar presentations
Programming for Beginners
Advertisements

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
P5, M1, D1.
Logic & program control part 3: Compound selection structures.
PSEUDOCODE & FLOW CHART
Chapter 2: Algorithm Discovery and Design
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Program Design and Development
Computer Science 1620 Programming & Problem Solving.
1 Chapter 8 Designing Small Programs. 2 A ‘Procedure’ v A set of instructions which describe the steps to be followed in order to carry out an activity.
Chapter 1 Program Design
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
BBS Yapısal Programlama (Structured Programming)1 From problem to program In “real world”… Problem in Natural language Top Down Design in pseudo-code.
Fundamentals of Python: From First Programs Through Data Structures
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Lecture 10 Instructor: Craig Duckett. Assignment 2 Revision TONIGHT DUE TONIGHT Wednesday, August 5 th Assignment 3 NEXT DUE NEXT Monday, August 10 th.
1 Shawlands Academy Higher Computing Software Development Unit.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Developing a Program.
Simple Program Design Third Edition A Step-by-Step Approach
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
Programming Lifecycle
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
Chapter 3 Developing an algorithm. Objectives To introduce methods of analysing a problem and developing a solution To develop simple algorithms using.
Lecture 2: Classes and Objects, using Scanner and String.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
By the end of this session you should be able to...
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 15: More-Advanced Concepts.
Developing an Algorithm
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
I Power Higher Computing Software Development The Software Development Process.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 12: Programming Project.
Logic Our programs will have to make decisions in terms of what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 6: Object-Oriented Programming.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Developing an Algorithm. Simple Program Design, Fourth Edition Chapter 3 2 Objectives In this chapter you will be able to: Introduce methods of analyzing.
The Software Development Process
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
Intermediate 2 Computing Unit 2 - Software Development.
The Hashemite University Computer Engineering Department
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Algorithms and Pseudocode
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 6: Stepwise refinement revisited, Midterm review.
Low-Level Programming Languages, Pseudocode and Testing Chapter 6.
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Lecture 2 Introduction to Programming
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Chapter 4 – Control Structures Part 1
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Problem Solving Techniques
Coding Concepts (Basics)
Problem Solving Skill Area 305.1
Software Development Process
Week 4 Lecture-2 Chapter 6 (Methods).
Basic Concepts of Algorithm
Presentation transcript:

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session

Revision of Sessions 1-4 So far, we’ve seen the basics of the Java language. We’ve seen many common data types: int, char, String, boolean and others. We can branch our code using if and switch statements. We can repeat tasks many times using for loops, while loops and do-while loops.

Session 5 - aims & objectives Later, we will go through an example which includes all the material covered so far. Plenty of time to ask questions, or recap past material. First, let’s think about how to assemble a complicated program. Software design Software testing

Software design There is a difference between program design and coding Effective programming requires both Program design is a formalised process Describe the problem in logical steps Test the description Refine the description Test the refinements Code the program Coding without design should always be avoided

Top-down design Most widely favoured method of program development The task is described as a problem The problem is divided into sub-problems Sub-problems are further divided, until the stages are easily represented by program code

Program description State the problem in hand Make this clear and precise May need clarification from the 'client' This problem statement can be broken down into partly or completely separate components Functional specification Usually for large programming projects This must be a written document agreed by all parties e.g. 'clients', 'programmers'

Algorithms An algorithm is the solution for a problem Algorithms must be: Finite: there must be a measurable point at which the problem can be said to be solved Ordered: the algorithm must consist of a series of steps Unambiguous: each step must follow on from a previous step – if choices are made they must be based on conditions determined earlier in the sequence

Top Tip!! When designing your algorithms... START WITH A PEN AND PAPER!! Until you can write the solution down clearly on paper, you’re not likely to be able to code it effectively.

Pseudocode A detailed description of a program Half way between programming syntax and human- readable English. Ignores specific programming syntax Provides enough detail so that each part of the description can correlate to actual source code In object-oriented programming, try to design pseudocode in an object-oriented manner (use external classes and methods)

Successive refinement First – develop an initial solution Does not involve a lot of detail or program code Must describe the solution correctly Secondly – refine this solution Each stage considered as a problem in its own right This solution must be described correctly Continue until the problem is completely solved 'successive refinements' Pseudocode

Example of program design – 1 Problem: write a program that prompts the user for 3 integers, and then writes out the total and the average numbers to the console Example output: Enter three integers: Total: 54 Average: 18

Example of program design – 2 Successive refinement: Initial description Prompt user for 3 integers Add the numbers together Work out the average Display the total and average to the console Refinement of first action Refinement of second action Refinement of third action Refinement of fourth action

Example of program design – 3 Refinement of first action Display prompt asking user to input 3 integers Read in values for int1, int2 and int3 Refinement of second action Set up a variable to store the sum Sum = int1 + int2 + int3

Example of program design – 4 Refinement of third action Set up a variable to store the average Average = sum/3 Refinement of fourth action Display the total to the console Display the average to the console

Testing a program design Desk tracing Data values are chosen Actions of program carried out by hand-tracing the program steps using these values Can be done on paper (with or without a calculator) Assertion testing Test the logic of the algorithm Describe the state of the program at any one point Consider what the effects are, of the next step being applied Repeat for entire algorithm

Example - assertion testing Assertion: when the 3 numbers are entered their values are stored in int1, int2 and int3 Assertion: sum is assigned the total of int1, int2 and int3 Assertion: average is assigned the value of sum divided by 3

Coding and testing When the design is considered sound, the program is coded Each line of pseudocode is replaced by real code The code is compiled and syntax errors are fixed The program is tested with lots of variations of data sets (including extreme ones)

State the problem Is it feasible? Plan and refine an action sequence Does it solve the problem? Write and compile the source code Is it free of syntax errors? Run the program Are the results correct? Run the program Does it do the job? Yes No Yes No Yes No Yes No Hooray! Yes PROGRAM DESIGN PROGRAM DESIGN

Coding hints Start coding with a template that you know works properly Make very small additions/changes and test the partly- finished code: Syntax errors – does it compile properly? Functionality – does it run correctly? Fix errors as they occur (or comment them out) Don't write a complete program and expect it to work the first time – it probably won't! Use a good coding style (neat indentations and comments)

Coding style Write code that is easy to understand: Identifiers should be meaningful e.g. hours rather than h Presentation of code should reflect its structure Indent code blocks, have matching braces in the same column Actions in the code should be commented Comments should add meaning, not repeat information already in the code e.g. int3=int1+int2 // add numbers int3=int1+int2 // int3 is sum of int1 + int2  not very useful this is more useful

Example of bad style class abc {public static void main(String []args) {int a=3,b=7,c; if (a>0) { c=a+b; else c=a} System.out.println(c); }}

Example of good style /* Program to display the value of c to the console */ class displayValue { public static void main(String []args) { int a=3,b=7,c; //set values of integers a and b if (a>0) { c=a+b } // if condition sets value of 'c' else { // dependent on value of 'a' c=a } System.out.println(c); //print value of 'c' to }//console }

Revision task – Fizzbuzz! Fizzbuzz is a counting game played in schools. Going around the room, each person takes it in turns to count a number, but... If the number contains a 3 or is divisible by 3, they must say “Fizz” instead of the number. If the number contains a 7 or is divisible by 7, they must say “Buzz” instead of the number. If both of the above are true, they must say “Fizzbuzz” instead of the number. If you get it wrong, you’re out! Task: Write a Fizzbuzz simulator which prints a table of numbers, replacing some numbers by “Fizz”, “Buzz” or “Fizzbuzz” appropriately.

Coming up in Session 6... Object Oriented Programming!!