02VariablesAndExpressions

# 02VariablesAndExpressions - CSE 114 Computer Science I...

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

CSE 114 – Computer Science I Niagara Falls, Ontario/New York

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

View Full Document
What is an algorithm? a sequential set of steps used to solve a problem
Design, then code Generalized steps of software engineering: 1. Understand and define the problem 2. Determine the required input and output 3. Design an algorithm to solve the problem by computer 4. Implement (code) the solution 5. Debug and test the software 6. Maintain and update the software Which is the most challenging step?

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

View Full Document
Designing a Program Example Problem: you have to give someone change what coins do you give that person? Requirements: make a program to do this takes user input displays the change breakdown as output
1. Understand and Define the Problem What are the needs of the program? ask user for input US coins (quarter, dime, nickel, penny) max change: 99¢ display coin output Typically done through Requirements Analysis

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

View Full Document
Who performs a Requirements Analysis? IT people What’s involved? interview users What are their expectations? What data do they need to access? Etc. write a requirements analysis report
2. Determine Input and Output Typed input by user: Amount of change requested (an integer between 1 and 99) Printed output: Number of quarters given Number of dimes given Number of nickels given Number of pennies given

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

View Full Document
3. Design an algorithm A. How many quarters? subtract the number of quarters X 25 from the total A. How many dimes? subtract the number of dimes X 10 from remaining total A. How many nickels? subtract the number of nickels X 5 from remaining total A. How many pennies? the remaining total
3. Design an algorithm (continued) Pseudocode: User Input originalAmount numQuarters originalAmount div 25 remainder originalAmount mod 25 numDimes remainder div 10 remainder remainder mod 10 numNickels remainder div 5 remainder remainder mod 5 numPennies remainder Output numQuarters Output numDimes Output numNickels Output numPennies

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

View Full Document
4. Code your solution import java.util.Scanner; public class ChangeMaker { public static void main(String[] args) { int change, rem, qs, ds, ns, ps; System. out.print("Input change amount (1-99): "); Scanner input = new Scanner(System. in); change = input.nextInt(); qs = change / 25; rem = change % 25; ds = rem / 10; rem = rem % 10; ns = rem / 5; rem = rem % 5; ps = rem; System. out.println(qs + " quarters"); System. out.println(ds + " dimes"); System. out.println(ns + " nickels"); System. out.println(ps + " pennies"); } // main } // class ChangeMaker
5. Debugging and Testing What’s the difference? What’s a bug?

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/13/2010 for the course CSE 114 taught by Professor Tashbook during the Spring '08 term at SUNY Stony Brook.

### Page1 / 52

02VariablesAndExpressions - CSE 114 Computer Science I...

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

View Full Document
Ask a homework question - tutors are online