02VariablesAndExpressions

02VariablesAndExpressions - CSE 114 Computer Science I...

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

View Full Document Right Arrow Icon
CSE 114 – Computer Science I Niagara Falls, Ontario/New York
Background image of page 1

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

View Full DocumentRight Arrow Icon
What is an algorithm? a sequential set of steps used to solve a problem
Background image of page 2
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?
Background image of page 3

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

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

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

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

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

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

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

View Full DocumentRight Arrow Icon
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
Background image of page 10
5. Debugging and Testing What’s the difference? What’s a bug?
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online