1 / 14

Moving To Code

3. Moving To Code. 3. More on the Problem-Solving Process. The final step in the problem-solving process is to evaluate and modify (if necessary) the program. 3. Coding the Algorithm into a Program. Problem Specification:

kimo
Download Presentation

Moving To Code

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 3 Moving To Code

  2. 3 More on the Problem-Solving Process • The final step in the problem-solving process is to evaluate and modify (if necessary) the program

  3. 3 Coding the Algorithm into a Program Problem Specification: Create a program that prompts the user for two integers, adds the two numbers together, then displays the result.

  4. 3 IPO Chart for the Floating Point Adder

  5. 3 Assigning Names, Data Types, and Initial Values to the IPO Items • Programmers use the information in the IPO chart to code the algorithm • First, the programmer assigns a descriptive name to each unique input, processing, and output item listed in the IPO chart • In most programming languages, these names can contain only letters, numbers, and the underscore; they cannot contain punctuation characters or spaces • Most Java programmers use lowercase letters for the names, capitalizing the first letter of subsequent words if necessary

  6. 3 Assigning Names, Data Types, and Initial Values to the IPO Items • The programmer also assigns a data type to each input, processing, and output item • The data type specifies the type of data each item represents • In addition to assigning both a name and data type to each input, processing, and output item, the programmer also assigns an initial value • This is referred to as initializing the item • Variables are simply computer memory locations that the program will use while running 4

  7. 3 Assigning Names, Data Types, and Initial Values to the IPO Items

  8. 3 Assigning Names, Data Types, and Initial Values to the IPO Items • The word double, which must be typed using lowercase letters, is a keyword in Java • A keyword is a word that has a special meaning in a programming language • Notice that each of the variable declaration instructions ends with a semicolon (;) • The instruction to declare a variable is considered a statement, which is simply a Java instruction that causes the computer to perform some action after it is executed, or processed, by the computer • All Java statements must end with a semicolon

  9. 3 Translating the Algorithm Steps into Java Code • After assigning a name, data type, and initial value to each input, processing, and output item, the programmer then translates each step in the algorithm into one or more Java instructions • In Java, you use streams, which are just sequences of characters, to perform standard input and output operations • The standard output stream is called System.out which refers to the computer screen

  10. 3 Translating algorithm steps into Java Code

  11. 3 Translating algorithm steps into Java Code

  12. 3 Desk-Checking the Program • Desk-check every program to make sure that each step in the algorithm was translated correctly

  13. 3 Evaluating and Modifying the Program • The final step in the problem-solving process is to evaluate and modify (if necessary) the program • Programmers often refer to this as the “testing and debugging” step • Testing refers to running (executing) the program, along with sample data, on the computer • Debugging refers to the process of locating and removing any errors, called bugs, in a program

  14. 3 Evaluating and Modifyingthe Program • Program errors can be either syntax errors or logic errors • You create a syntax error when you enter an instruction that violates the programming language’s syntax • Logic errors, on the other hand, are much more difficult to find, because they can occur for a variety of reasons

More Related