3.4 Simple Arithmetic Expressions | 111
//**
// FreezeBoil application
// This application computes the midpoint between
// the freezing and boiling points of water
//**
public classFreezeBoil
{
public static voidmain(String[] args)
{
final doubleFREEZE_PT = 32.0; // Freezing point of water
final doubleBOIL_PT = 212.0; // Boiling point of water
doubleavgTemp; // Holds the result of averaging
// FREEZE_PT and BOIL_PT
// Display initial data
System.out.print("Water freezes at "+ FREEZE_PT);
System.out.println(" and boils at "+ BOIL_PT + " degrees.");
// Calculate and display average
avgTemp = FREEZE_PT + BOIL_PT;
avgTemp = avgTemp / 2.0;
System.out.println("Halfway between is "+ avgTemp + " degrees.");
}
}
The application begins with a comment that explains what the application does. Inside the
classis a declaration section where we declare themainmethod, which includes declarations
of the constantsFREEZE_PTandBOIL_PTand the variableavgTempand then a sequence of exe-
cutable statements. These statements display the initial data, addFREEZE_PTandBOIL_PT,di-
vide the sum by 2, and then show the result. Here is the output from the application: