140 likes | 278 Vues
This guide provides a comprehensive overview of the problem-solving process in programming, focusing on Java. It covers key steps including evaluating and modifying programs, coding algorithms, and using IPO charts to assign names, data types, and initial values to program elements. You'll learn how to translate algorithm steps into Java code, including the use of keywords and syntax rules, as well as the importance of desk-checking, testing, and debugging to ensure program correctness. This resource is aimed at beginners eager to grasp fundamental concepts in Java programming.
E N D
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: Create a program that prompts the user for two integers, adds the two numbers together, then displays the result.
3 IPO Chart for the Floating Point Adder
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
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
3 Assigning Names, Data Types, and Initial Values to the IPO Items
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
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
3 Translating algorithm steps into Java Code
3 Translating algorithm steps into Java Code
3 Desk-Checking the Program • Desk-check every program to make sure that each step in the algorithm was translated correctly
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
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