/* Name: Mahmoud Elsaftawy
Date: March 31, 2008
Teacher: Mr. Sayed
Class: ICS3M0
This program gets the previous and present readings
of water entered by the user and calculates the amount
of water used in the previous month
*/
// The "MElsaftawy_ICS3M_2_2_5" class.
import java.awt.*;
import hsa.Console;
public class MElsaftawy_ICS3M_2_2_5
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
//Declare variables for the previous and present reading of water
int previousRead, presentRead;
//Idiot Proof Loop
//Ask for the previous reading of water
do
{
c.print ("Enter the previous reading of water in 5 digits: ");
previousRead = c.readInt (); // get the user input
}
while (previousRead < 0 || previousRead > 99999);
//Ask for the Present reading of water
do
{
c.print ("\nEnter the present reading of water in 5 digits: ");
presentRead = c.readInt (); // get the user input
}
while (presentRead < 0 || presentRead > 99999);
if (previousRead < presentRead)
{
c.println ("\nThe amount used in the present month is " + (presentRead - previousRead));
}
else
{
c.println ("\nThe amount used in the previous month is " + (previousRead - presentRead));
}
} // main method
} // MElsaftawy_ICS3M_2_2_5 class