Variables

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

Either, or both. This is a design decision.

Variables

Floating point would probably be best for a real application, but, to simplify things let us:

  • Convert the input string to an int variable.
  • Evaluate the formula using integer arithmetic.
  • Save the result as an int variable.

This work will by done by the convert() method. Here is a sketch of the code:

// The application
public int convert( int F )  
{
  return ( (F-32) * 5 ) / 9;
}

You could continue on from here and develop a non-GUI application where the main() method does input and output with the keyboard and monitor. You might do this if you wanted to debug the application code first before working on the GUI. However, this example will do input and output with GUI components.

QUESTION 3:

Now give some thought to the graphical interface.

  • Into what type of GUI component will the user enter the Fahrenheit temperature?
  • What type of GUI component will display the result?