Mock test review Revision of Activity Diagrams for Loops,

Slides:



Advertisements
Similar presentations
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Advertisements

Revision and test review. int s = 10; int r; for(r=0; r
Some revision.  Today, we will do some revision on: - ◦ booleans, and ◦ if statements.
2  An instruction or group of instructions need to be repeated several times.  2 types of iteration: 1.You do not know how many times you will need.
 Demonstrate use of a “for loop” in the design and development of a Java program to calculate the total of a one-dimensional array of 6 integers.  Design.
COMP 14 Introduction to Programming Mr. Joshua Stough February 16, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 6, 2005.
COMP 14 Introduction to Programming Miguel A. Otaduy May 21, 2004.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
Copyright 2006 by Pearson Education 1 reading: 4.1 Cumulative sum.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Loops Chapter 4. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while” structures.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
Lecture 10 Instructor: Craig Duckett. Assignment 2 Revision TONIGHT DUE TONIGHT Wednesday, August 5 th Assignment 3 NEXT DUE NEXT Monday, August 10 th.
Introduction to Computer Programming Counting Loops.
Java Programming: From the Ground Up
Chapter 6: Iteration Part 1. To be able to program loops with the while, for, and do statements To avoid infinite loops and off-by-one errors To understand.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Programming with C# Iteration LECTURE 3. Summary of last lecture SequenceSelectionif and switch statementsCastingRandom.
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
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 5 Loops.
BUILDING JAVA PROGRAMS CHAPTER 2 Days of For Loops Past.
 Wednesday, 9/18/02, Slide #1 CS106 Introduction to CS1 Wednesday, 9/18/02  QUESTIONS?? HW #1 due today at 5!!  Today: Loops, and two new data types.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
By Chad Blankenbeker.  The for-loop is best used when you know how many times it is going to be looped  So if you know you want it to only loop 10 times,
CS101 Computer Programming I Chapter 4 Extra Examples.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Repetition Statements while and do while loops
Repetition. Control of Flow SEQUENCE SELECTION (if..else, switch…case) REPETITION.
1 BUILDING JAVA PROGRAMS CHAPTER 2 Pseudocode and Scope.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Java iteration statements ● Iteration statements are statements which appear in the source code only once, but it execute many times. ● Such kind of statements.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Nested for loops.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Application development with Java Lecture 6 Rina Zviel-Girshin.
Flow of Control: Loops Module 4. Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks.
CSE 501N Fall ’09 07: Iteration 17 September 2009 Nick Leidenfrost.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
CS 112 Introduction to Programming Loop Examples; Variable Scoping; Nested Loops; Yang (Richard) Yang Computer Science Department Yale University 208A.
COMP 110 Augustus Gloop, Augustus Gloop… Luv Kohli September 24, 2008 MWF 2-2:50 pm Sitterson 014.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
Comp1004: Loops and Arrays I Whiles, For and Arrays[]
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Slides by Evan Gallagher
Slides by Evan Gallagher
Chapter 6 More Conditionals and Loops
Loop Structures.
Building Java Programs
Building Java Programs
CSC 113 Tutorial QUIZ I.
Introduction to Computer Programming Counting Loops 2
Building Java Programs
Building Java Programs
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
Console.WriteLine(“Good luck!”);
Building Java Programs
CIS 110: Introduction to Computer Programming
Presentation transcript:

Mock test review Revision of Activity Diagrams for Loops, and Dry Run Example with “for” Loop

First – revision of loops Activity Diagrams need to include a diamond shape for questions if statements, or conditions controlling a loop [loop condition FALSE] [loop condition TRUE] [loop condition FALSE] [loop condition TRUE]

Activity Diagram for “do…while” The test is made after the loop body not before as in the while loop. This means the loop body is certain to be performed at least once. Loop Body [loop condition TRUE] [loop condition FALSE] Statement After Loop

Statement(s) After Loop Activity Diagram for “while” The test is made before the loop body not after as in the do … while loop [loop condition FALSE] This means the loop body may not be performed at all (if the condition is false the first time through he loop. [loop condition TRUE] Loop Body Statement(s) After Loop

Before next week, you need to complete the debugging and dry run on WOLF and then answer the questions in preparation for your test For the test, fill out the paper copy first and then answer the electronic test on Wolf If you have any difficulty, or don’t get the answers you expect, please ask for help next week during the tutorial or workshop.

Test 1 format Test 1 which is NOT open book consists of: - A dry run exercise which is worth 30 marks of your overall module assessment result. Twenty Jafa type questions worth a total of 10 marks. Test 1 has a maximum of 40 marks. Test 1 will be held on Thursday November 27th for most people. Anyone entitled to extra time for any reason will have their test on Tuesday morning starting at 10:00 am in MI214. Part-time students will have their test on Monday 24th starting at 10:00 am in MA112.

How the portfolio grade is calculated You must pass the on-line Jafa by answering at least 60% of the questions correctly. This does not affect your overall portfolio result, but if you don’t pass Jafa you cannot pass the module. Test 1 is worth 40% of the marks in total. Test 2 which is held in assessment week (programming exercises) is worth 60% of the marks in total.

Why test dry runs? By now, we expect you to be able to understand code, even if you can’t always make it compile and don’t always understand the errors you see. By asking you to debug, trace through code and explain code, we can check your overall understanding. The final test is a ‘live’ test of your programming skills; you will be required to design, code, and run programs under test conditions.

The test questions are shuffled and randomly allocated, so we don’t know in advance which student will get which questions. Today, we’re going to look at some of the questions involving loops to give you a bit of extra practice.

A simple for loop public class ForDemo { public static void main(String[] args){ for(int i=1; i<11; i++){ // for integer i equals one // while i is less than eleven // at each repeat add one to i System.out.println("Count is: " + i); } Straightforward, but it might be worth writing it up – ouputting 1 then separate line 2, etc, showing how it returns to the beginning of the loop each time. The first value for i is 1. The first output is: Count is: 1 The last output is Count is: 10 Why is the last output not Count is: 11 ? What value does i begin with? What is the first output? What is the last output?

Example dry run of nested for loops 1.public class Exercise1 { 2.public static void main(String [] args) { 3. int numRows = 4; 4. int numCols = 3; 5. for (int row = 1; row <= numRows; row++){ 6. for (int col = 1; col <= numCols; col++){ 7. System.out.print("*"); 8. } // end for 9. System.out.println(); 10. } // end for 11. } // end main program 12.} // end class Talk them through this, maybe sketching where row and col are at each run of the loop. (row 1, cols 1-6, row 2, etc) The class is called Exercise1. The main program is set up. Variable numRows is declared and given the value 4. Variable numCols is declared and given the value 3. First for loop uses control variable row. Second for loop uses control variable col. Now we will work out what will be printed out by the end.

How can we represent this as a dry run? First, set up the dry run

What happens after line 7?

We go back to the beginning of the nested loop. The conditions of the nested loop are still valid so we re-enter the loop. What happens when col = 3?

Have a look carefully at the code. The condition col < numCols is false so we leave the inner nested loop and go down to the next instruction on line 9 which is to output a new line. This reaches the end of the outer loop so we now return to line 5 where we add 1 to row and then continue ...

Complete Dry Run

Final Output ** (newline)

How to make sure you will pass test 1 Make sure that you have done all the exercises in all the workbooks to date. If you’re falling behind, you still have time before the test to catch up. Ensure that you are up to date with jafa. If you are having difficulty with dry runs, ask your tutor in the workshop or tutorial. We are here to help!