lecture8 - Administrative Issues Arrays Lecture 8 Homework...

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
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 Right Arrow Icon
Ask a homework question - tutors are online