START DEFINITIONS values (3) N1 = (8, 1,-9) i N1 average N3,2 sum N2 = 0 temp N1 Do not guess or assume any values! Follow the values of the variables.

Slides:



Advertisements
Similar presentations
1 Arrays An array is a special kind of object that is used to store a collection of data. The data stored in an array must all be of the same type, whether.
Advertisements

Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
1 Various Methods of Populating Arrays Randomly generated integers.
Computer and Programming
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Algorithms and Problem Solving
Variables – the Key to Programming. ICS-3M1 - Mr. Martens - Variables Part 1 What is a Variable? A storage location that is given a “name” You can store.
LECTURE 1 CMSC 201. Overview Goal: Problem solving and algorithm development. Learn to program in Python. Algorithm - a set of unambiguous and ordered.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
 Monday, 9/30/02, Slide #1 CS106 Introduction to CS1 Monday, 9/30/02  QUESTIONS (on HW02, etc.)??  Today: Libraries, program design  More on Functions!
An intro to programming The basic nitty-gritty that’ll make you scratch your head and say, “This is programming?”
Chapter Eight: Arrays 1.Terms and what they mean 2.Types of arrays -One Dimensional arrays -Two Dimensional arrays -ragged arrays -Parallel arrays 3. Methods.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
Chapter 7: User-Defined Methods
BUILDING JAVA PROGRAMS CHAPTER 7 Array Algorithms.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Functions A function is a snippet of code that performs a specific task or tasks. You use a multitude of functions daily when you do such things as store.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
Chapter 2 - Algorithms and Design
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
CECS 220 – Final Review By: Joseph M. Ouellet. Question 1 public boolean hammer(double force){ if(force >= NEEDED_FORCE){ int hammerTime = hammerGoHammer(force);
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
Conditional Execution
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
What does a computer program look like: a general overview.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
DT249-Information Systems Research Practice Programming Revision Lecture 2 Lecturer: Patrick Browne.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Methods We write methods in our programs for many reasons:
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
1 Methods Introduction to Methods Passing Arguments to a Method More About Local Variables Returning a Value from a Method Problem Solving with Methods.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Methods. Methods also known as functions or procedures. Methods are a way of capturing a sequence of computational steps into a reusable unit. Methods.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
Lecture 13: Arrays, Pointers, Code examples B Burlingame 2 Dec 2015.
S517 Web Programming Assistant Professor Xiaozhong Liu
LAB SESSION ONE DIMENSIONAL ARRAY.
CSCI 1226 FALL 2015 MIDTERM #1 REVIEWS.  Types of computers:  Personal computers  Embedded systems  Servers  Hardware:  I/O devices: mice, keyboards,
Review :chapters What is an algorithm? A step by step description of how to accomplish a task. For example, Adding 3 numbers N1, N2 and N3 Add.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Chapter 10 Arrays. Learning Java through Alice © Daly and Wrigley Objectives Declare and use arrays in programs. Access array elements within an array.
Arrays Chapter 6. Objectives learn about arrays and how to use them in Java programs learn how to use array parameters and how to define methods that.
Announcements Final Exam: TBD. Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Lecture 6: Methods MIT-AITI Kenya © 2005 MIT-Africa Internet Technology Initiative In this lecture, you will learn… What a method is Why we use.
Variables, Types, Operations on Numbers CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
For Friday Finish reading chapter 9 WebCT quiz 17.
IAS 1313: OBJECT ORIENTED PROGRAMMING Week 3: Data Type, Control Structure and Array Prepared by: Mrs Sivabalan1.
CSC111 Quick Revision.
Chapter 7 User-Defined Methods.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 7 User-Defined Methods.
Java for Beginners University Greenwich Computing At School DASCO
Introduction to Computer Science / Procedural – 67130
Java for Beginners.
SELECTION STATEMENTS (1)
Java for Beginners University Greenwich Computing At School DASCO
Building Java Programs
Variables, Types, Operations on Numbers
Variables, Types, Operations on Numbers
Building Java Programs
Unit 3: Variables in Java
Building Java Programs
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Methods/Functions.
Presentation transcript:

START DEFINITIONS values (3) N1 = (8, 1,-9) i N1 average N3,2 sum N2 = 0 temp N1 Do not guess or assume any values! Follow the values of the variables step by step. Carefully! This program might do wrong things too! (Actually, this program might have errors. It works, but not always like wanted). Your task is not to correct them, but to see which will be the values of the variables. Definitions and the drawing and writing style used in the flowcharts in this exam are correct and can be used as a model for your own flowcharts. values( 2 ) = values( 1 ) i <= 3 sum = sum + i i = i + 1 TRUE FALSE values( 1 ) = temp temp = values( 2 ) DISPLAY ”The sum is: ” sum average = sum / 6 DISPLAY ”The average is: ” average i = 1 END The first picture here The second picture here Programming 1 – Final exam Dec Task 1: (Do both Tasks 1 & 2 if not happy with the result of the first exam.) Look at the flowchart below. Draw two pictures showing the contents of the memory in that program. That is, draw the variables and data structures and the values inside them: 1.Right after the START (picture1) 2.Just before the END (picture2) Also put ”undefined” if the variable does not have a value yet. No material – Each task on separate paper – Name on every used paper – Return every paper Juhani Välimäki

Task 2: (Do both Tasks 1 & 2 if not happy with the result of the first exam.) Design with a flowchart a program that asks the user to input temperatures (N5,2) for each 7 days on the week. Save the values in an array called temperatures. Program should calculate the average of the temperatures and display that. Example test case (just an example, do not use fixed values in your program) displayed:user inputs: Give the temperature for the day 1: Give the temperature for the day 2: -1.5 Give the temperature for the day 3: Give the temperature for the day 4: Give the temperature for the day 5: 4.0 Give the temperature for the day 6: -15 Give the temperature for the day 7: 0.5 The average was Then program should ask the user to input a number of the day. While the number is between 1 and 7 the program displays the temperature of that day and asks for the next number. If the number is not between 1 and 7 program quits and tells how many times it was asked about the temperature of some real, existing day (=user gave a number between 1 and 7). Example output displayed: user inputs: Give a number of a day (1-7): 2 The temperature of the day 2 was Give another number of a day (1-7): 5 The temperature of the day 5 was 4.00 Give another number of a day (1-7): 8 You asked about the temperatures 2 times. Bye!.

Juhani Välimäki Task 3: The sequential file products contains the following information about each product: code AN5 nameAN10 priceN6,2 amountN4 (how much in the store right now) Design with a flowchart a program that reads all the products from the file products and selects those products whose amount is too small (<20) and writes them to another file called product_orders. The program displays nothing, just writes some of the products to the output file product_orders. Each record in the file product_orders is of type: code AN5 nameAN10 priceN6,2 amount N4 (how much should be ordered) The amount of how much should be ordered is calculated with: amount = amount (old amount in the store right now) SOME FILE RELATED DEFINITIONS customers, sequential file TYPE T_CUSTOMER xxxxx AN 1 cust T_.... FILE RELATED COMMANDS IN FLOWCHART OPEN customers (R), other (W) READ... ->... WRITE... ->... CLOSE customers, other Tasks 3 & 4 are for everybody.

Task 4: Write a Java program corresponding the flowchart below. Think first. (Where should the subroutine definition be and so on) class Task4 // help for you { public static void main(String[] args) {... double d... int num... String str... boolean isClosed... System.out.println(”Give the price for product ” + i );...double some = Keyboard.readDouble();...string1.equals(”Some text”)... if( a = = b ) { } Juhani Välimäki START Main program DEFINITIONS numbers (100) N4,2 i N3 num N2 sum N6,2 = 0 ttt AN7 = ”Sum was” START RETURN ( half ) SUBROUTINE split_Into_Two( value N2 ) N4,2 DEFINITIONS precise N4,2 half N4,2 half = precise / 2 Tasks 3 & 4 are for everybody. i <= 100 TRUE FALSE DISPLAY ”Give a number: ” ACCEPT num END i = i + 1 numbers( i ) = CALL split_Into_Two( num ) DISPLAY ttt ”: ” sum sum = sum + num sum = sum / 2 i = 1 precise = value ttt == ”Sum was” TRUE FALSE DISPLAY ”impossible” This program is just an example. The program has no other meaning than testing Your Java skills! Good Luck! Flowchart syntax and drawing style are correct and can be used as a model.