Programming Exercises

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.

Chapter 61 Programming Exercises


Exercise 1 — Temperature Conversion

Modify the temperature conversion program so that it converts Celsius to Fahrenheit. Use the formula:

fahr = celsius*9/5 + 32
Click here to go back to the main menu.

Exercise 2 — Two Way Conversion

Add two buttons to the temperature conversion program. Clicking one button converts Fahrenheit to Celsius, clicking the other converts Celsius to Fahrenheit. Set to "noneditable" whichever text field is to contain the result of the conversion. Add a "clear" button that clears the text in both text fields.

Click here to go back to the main menu.

Exercise 3 — User-friendly Fat Calculator

Modify the calories from fat calculator so that it does not crash when the user enters text that cannot be converted to a double. You might have to look ahead to chapters 80 and 81 for this, or look at the modification done with the temperature converter and try to do something similar.

Click here to go back to the main menu.