# lecture8 - Administrative Issues Arrays Lecture 8 Homework...

This preview shows pages 1–4. Sign up to view the full content.

Arrays Lecture 8 Administrative Issues • Homework 1 due now • Program 2 ongoing – Due Wednesday June 4 Problem from Yesterday Yesterday’s Sample Problem Programming Project 3.4 – Design and implement an application that reads an integer value and prints the sum of all even numbers between 2 and the input value. Print and error message if the input is less than 2. • In groups of 3-6, apply the problem solving process to this project • We’ll code and test it together Establish the requirements Create a design Implement the code Test the implementation Sample Problem • Step 1 is to understand the problem – This comes from the problem description itself • Programming Project 3.4 – Design and implement an application that reads an integer value and prints the sum of all even numbers between 2 and the input value. Print and error message if the input is less than 2. Breaking It Up Into Pieces • Reading the number from the user • Validating the input (number at least 2) • Compute the sum of even numbers • Display the sum

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Solution Design • Reading the number from the user – Print “Enter a number above 1:” to the screen – Read the value and store in value variable • Validating the input (number at least 2) – if value < 2, then print “Error. Invalid value.” Solution Design • Compute the sum of even numbers – set the total to zero for loop from 2 until value, incrementing by 2 • add the loop variable to total • Display the sum – Print total to the screen Solution Refinement • Compute the sum of even numbers – Would a while or do loop be better than a for loop? – No, we know how many iterations • It depends on the value entered by the user • No refinement needed Implementation • JBuilder… Testing • Run the program with known answers • Known solutions called Test Cases – Input 0 Output ERROR – Input 1 Output ERROR – Input 2 Output 2 – Input 3 Output 2 – Input 4 2+4 Output 6 – Input 5 2+4 Output 6 – Input 6 2+4+6 Output 12 Arrays
Variables and Data Types • Variables hold a single value – Each variable has a type • For large tasks, individual variables are impractical – Example: StudentCentral’s list of PIDs

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/15/2009 for the course ASTRONOMY 1000 taught by Professor Kim during the Spring '01 term at Yonsei University.

### Page1 / 7

lecture8 - Administrative Issues Arrays Lecture 8 Homework...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online