02VariablesAndExpressions

02VariablesAndExpressions - CSE 114 Computer Science I...

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

View Full Document Right Arrow Icon
CSE 114 – Computer Science I Variables & Expressions Niagara Falls, Ontario/New York
Image of page 1

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

View Full Document Right Arrow Icon
Algorithms & Software Engineering What is an algorithm? a sequential set of steps used to solve a problem
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?
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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
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
Image of page 7

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

View Full Document Right 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
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
Image of page 9

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

View Full Document Right 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
Image of page 10
5. Debugging and Testing What’s the difference? What’s a bug? Note, this step may lead to a feedback loop To step 4 to fix bugs, improve performance, etc.
Image of page 11

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern