ITP © Ron Poet Lecture 4 1 Program Development. ITP © Ron Poet Lecture 4 2 Preparation Cannot just start programming, must prepare first. Decide what.

Slides:



Advertisements
Similar presentations
Created by Gwendolyn Best
Advertisements

Topic Reviews For Unit ET156 – Introduction to C Programming Topic Reviews For Unit
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
4 Control Statements: Part 1.
Telling Time Part 2 Deutsch 1
Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 1 C++ Basics. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 1-2 Learning Objectives Introduction to C++ Origins, Object-Oriented.
Copyright © 2003 Pearson Education, Inc. Slide 1.
BASIC SKILLS AND TOOLS USING ACCESS
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
Credit hours: 4 Contact hours: 50 (30 Theory, 20 Lab) Prerequisite: TB143 Introduction to Personal Computers.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Multiplying binomials You will have 20 seconds to answer each of the following multiplication problems. If you get hung up, go to the next problem when.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Around the World AdditionSubtraction MultiplicationDivision AdditionSubtraction MultiplicationDivision.
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
Lecture 24. In last lecture we have discussed need and advantage of file handling in development of programs. File handling enhance scope of our programs.
Mike Scott University of Texas at Austin
© Vinny Cahill 1 Writing a Program in Java. © Vinny Cahill 2 The Hello World Program l Want to write a program to print a message on the screen.
Chapter 7: Arrays In this chapter, you will learn about
Find the total of 5 hours 10 minutes 3 hours 23 minutes 6 hours 39 minutes Click for solution + hours minutes7214 More than 60 minutes? YES: convert 60.

Arrays Dr. Jey Veerasamy July 31 st – August 23 rd 9:30 am to 12 noon 1.
ABC Technology Project
Access Lesson 13 Programming in Access Microsoft Office 2010 Advanced Cable / Morrison 1.
1 / / / /. 2 (Object) (Object) –, 10 (Class) (Class) –, –, – (Variables) [ Data member Field Attribute](, ) – (Function) [ Member function Method Operation.
Programming Methodology (1). public class Hello { public static void main(String[] args) { System.out.println("Hello world"); } } Hello world.
A Key to Economic Analysis
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
CREATING A PAYMENT REQUEST FOR A NEW VENDOR
Squares and Square Root WALK. Solve each problem REVIEW:
We are learning how to read the 24 hour clock
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Problem Solving and Algorithm Design
David Walker Ottawa TMG Users Group 15 March 2014.
1 Review Quisioner Kendala: Kurang paham materi. Praktikum Pengaruh teman.
Introduction Exponential equations are equations that have the variable in the exponent. Exponential equations are found in science, finance, sports, and.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Addition 1’s to 20.
25 seconds left…...
Test B, 100 Subtraction Facts
Chapter Three Arithmetic Expressions and Assignment Statements
Week 1.
Number bonds to 10,
Types of selection structures
We will resume in: 25 Minutes.
CHAPTER 11 FILE INPUT & OUTPUT Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
11.2 Arithmetic Sequences & Series
1 PART 1 ILLUSTRATION OF DOCUMENTS  Brief introduction to the documents contained in the envelope  Detailed clarification of the documents content.
Introduction to Recursion and Recursive Algorithms
1 Lecture 16:User-Definded function I Introduction to Computer Science Spring 2006.
L6:CSC © Dr. Basheer M. Nasef Lecture #6 By Dr. Basheer M. Nasef.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 3 Loops.
By Senem Kumova Metin 1 DATA TYPES. by Senem Kumova Metin 2 DATA TYPE? …… x; // DECLARATION OF VARIABLE X printf(“Do you want to go on? \n”) printf(“Please.
ITP © Ron Poet Lecture 13 1 Helper Objects. ITP © Ron Poet Lecture 13 2 Console Helper Object  We have used Console objects for a while, let’s see what.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
ITP © Ron Poet Lecture 5 1 Branching. ITP © Ron Poet Lecture 5 2 CookTime After Midnight  We want to improve our program so that we can cook meals after.
C# Programming Methods.
Presentation transcript:

ITP © Ron Poet Lecture 4 1 Program Development

ITP © Ron Poet Lecture 4 2 Preparation Cannot just start programming, must prepare first. Decide what the program will do. Then how it will do it. Testing strategy – does it work?

ITP © Ron Poet Lecture 4 3 English Description Write down what the program will do. Normally given to you on this course. PSD will teach techniques for finding this out. We want a program to tell us when to put the meat in the oven so that it will be done on time.

ITP © Ron Poet Lecture 4 4 Scope of the Program Next, work out what the program will do and what it will not do. Again, you will be told this on this course. Cooking time varies for different types of meat but has a general formula, so many minutes per kilo plus a fixed extra time. We will expect the user to look this up in a cookbook and enter it in the program. So our program will not know the cooking times for all types of meat.

ITP © Ron Poet Lecture 4 5 User Interaction Next, work out how the user will interact with the program. What information will they give the program. What information will be returned. What form will this interaction take? The user will interact via a Console window. They will be prompted for input and then given the desired start time.

ITP © Ron Poet Lecture 4 6 Sample Data Prepare an actual example of how the program will be used. Normal use – happy day scenario. The user wishes to cook a 2 kilo joint of meat, with formula 40 minutes per kilo + an extra 50 minutes. The want the meat to be ready at 730 pm.

ITP © Ron Poet Lecture 4 7 Expected Output Calculate the expected output by hand. Choose easy numbers if possible. Cooking time is 2 * = 130 minutes Start time is 730 – 130 minutes = 520 pm.

ITP © Ron Poet Lecture 4 8 Sequence of Activities Now work out what our program has to do as a sequence of activities. Write it in English, being guided by the sample data. Get cooking formula. Get finish time. Calculate cooking time. Output oven switch on time.

ITP © Ron Poet Lecture 4 9 Other Sequences Appear the Same The following sequence look the same to the user. It does not matter which one we choose. Get cooking formula. Calculate cooking time. Get finish time. Output oven switch on time.

ITP © Ron Poet Lecture 4 10 Other Sequences Solve the Same Problem Differently We could get the required information from the user in a different order. The user interaction is different, but the same problem is solved. Get finish time. Get cooking formula. Calculate cooking time. Output switch on time.

ITP © Ron Poet Lecture 4 11 Special Algorithms How do we do calculations with time? Convert times from hours and minutes to total minutes. Times like 730 are integers. Hours are time / 100, minutes are time % 100. Total minutes are 60 * hours + minutes. Do arithmetic in total minutes. Convert back to hours and minutes. Hours are total minutes / 60. Minutes are total minutes % 60.

ITP © Ron Poet Lecture 4 12 Problem Scenarios Note things that might go wrong. Total cook time of 2 hours with finish time of 130 pm. Start time should be 1130am. How likely is this. Very likely for Sunday lunch. Solution Use a 24 hour clock for times. Assume users will not be cooking over midnight.

ITP © Ron Poet Lecture 4 13 Assign Work to Objects Go back to the sequence of activities and allocate objects for each activity. Get cooking formula.Console Get finish time.Console Calculate cooking time.main Output switch on time.Console

ITP © Ron Poet Lecture 4 14 Write a Skeleton Program The first version of our program should have comments for each activity. As well as defining the main object. public class CookTime{ public static void main(String[] arg) { // input cooking time parameters // input finish time // calculate cooking time // output start time }

ITP © Ron Poet Lecture 4 15 Step by Step Development Add activities one by one and run the program, making sure it works at each step. Add trace statements if necessary to check the values of key variables. System.err.println(); Check the accuracy with hand calculations.

ITP © Ron Poet Lecture 4 16 input cooking time parameters Console con = new Console("Cooking Helper"); con.print("Enter mins per kg: "); int minsPerKg = con.readInt(); con.print("Enter extra mins: "); int extraMins = con.readInt(); con.print("Enter meat weight in kg: "); double weight = con.readDouble();

ITP © Ron Poet Lecture 4 17 input finish time con.print("Enter finish time using 24 hour clock: "); int time = con.readInt();

ITP © Ron Poet Lecture 4 18 calculate cooking time int cookTime = (int) (minsPerKg * weight + extraMins); int endHours = time / 100; int endMins = time % 100; int endTotalMins = 60 * endHours + endMins; int startTotalMins = endTotalMins - cookTime; int startHours = startTotalMins / 60; int startMins = startTotalMins % 60;

ITP © Ron Poet Lecture 4 19 output start time String out = String.format(%02d%02d, startHours, startMins); con.print("Put meat in oven at + out);

ITP © Ron Poet Lecture 4 20 Run The Program

ITP © Ron Poet Lecture 4 21 Recap English description of Task Scope of the program. Interaction with users. Sample data. Sequence of activities. Expected output. Special algorithms.

ITP © Ron Poet Lecture 4 22 Recap (2) Problem scenarios and their resolution. Assign work to objects. Write skeleton program. Step by step development. Proverb – There is never time to do it right, but always time to do it over.

ITP © Ron Poet Lecture 4 23 Example 2 A bank account is a permanent record that Remembers how much money you have. Allows you to update the amount. Write a program that uses a file to store a bank account. The program should Read the current amount from the account. Get a transaction (adding or subtracting money) from the user. Write the updated amount back to the file.