Java Reference
In-Depth Information
Programming Assignments
1 Writing Java Code from Pseudocode
Start TextPad. Open the Java source code file SimpleMath.java from the
Chapter03 folder on the Data Disk. Using the techniques you learned in this
chapter, write the lines of code inside the main() method to perform the simple
math operations, as outlined by the pseudocode in Table 3-19.
Table 3-19
Pseudocode for Simple Math Program
Begin SimpleMath
Get Data
Get first integer from user
Get second integer from user
End Get Data
Perform Math
Calculate sum: first + second
Calculate difference: first - second
Calculate product: first * second
Calculate quotient: first / second
End Perform Math
Display all answers
End
1. With the SimpleMath.java source code displayed in the TextPad coding
window, insert your name and date in the comments. Insert an appropriate
purpose comment. Change the name of the program to MathProgram in
the class header and comments.
2. Click inside the main() method braces.
3. Begin by entering the declaration statements to declare the following
variables:
declare string variables for user input
declare integer variables to store the user input after it has been parsed
declare integer variables to store the sum, difference, and product
declare a double variable to store the quotient
4. After studying the pseudocode in Table 3-19, enter the lines of code neces-
sary to produce the output.
5. Save the file on the Data Disk with the file name MathProgram.
6. Compile the program. If errors occur, fix them in the TextPad coding
window and compile again.
7. Run the program. If the program runs correctly, return to TextPad and
print a copy of the source code. Otherwise, return to Step 3, review the
code, and correct the errors until the program runs error-free.
 
Search WWH ::




Custom Search