APCS Notes 2.6 - Pg # of #
2.6: Temperature Conversion Program
Intro: Today, we talk about inputs - the ability for the user to interact with the program.
You can follow along on pgs 38-40.
import TerminalIO.KeyboardReader;
Import statements make use of existing Java classes so you dont have to rewrite the code for it!KeyboardReader reader = new KeyboardReader()
Instantiatinga KeyboardReader object. We decided to call the object reader.
SomeClass someObject = new SomeClass();
double fahrenheit; double celsius;
We are defining two variables here.Programming Tip: Define variables in lowercase
(This names a location in RAM where a number will be stored.) The value of the variable may change (hence the name variable!) but the name will not.
double refers to the type of variable - in this case floating point numbers.
Here, the reader object responds to the message readDouble by waiting for the user to input a value and press enter. Then the number is stored as a value for fahrenheit.Note: The parameter parentheses are still required even though there were no parameters for the message.
Just telling the system to print the value of the variable celsius.Note: So we see that System.out.println can be used to display a variable, text (string) or even an expression!
Designed to prevent the terminal window from disappearing after the JVM executes the program. Sending the pause message to the reader object displays the message Press Enter to Continue ... in the terminal window, thus pausing the program.