// Scott DeRuiter 7/1/2002 // Balloon.java // A Balloon that rises and falls, to be used by clients public class Balloon { double altitude; double elapsedtime; double oldaltitude; double oldelapsedtime; public Balloon ( ) { altitude = 0.0; elapsedtime = 0.0; oldaltitude = 0.0; oldelapsedtime = 0.0; } public void ChangeAlt ( double change, double newtime ) { oldaltitude = altitude; oldelapsedtime = elapsedtime; altitude += change; elapsedtime += newtime; } public double Rate ( ) { return ( ( altitude - oldaltitude ) / ( elapsedtime - oldelapsedtime ) ); } public double SendTime ( ) { return elapsedtime; } public double SendAlt ( ) { return altitude; } } // Scott DeRuiter 7/1/2002 // BalloonFlight.java // Simulates the flight of a balloon using the Balloon class. // 7/15/2011 - Greenstein: Changed TextReader to Scanner import java.util.Scanner; public class BalloonFlight { public static void main ( String [] args ) { double alt, time; Scanner input = new Scanner ( System.in ); Balloon myballoon = new Balloon ( ); System.out.println ( "Altitude = " + myballoon.SendAlt ( ) ); System.out.println ( "Time = " + myballoon.SendTime ( ) ); System.out.print ( "\n\nEnter the change in altitude -> " ); alt = input.nextDouble ( ); System.out.print ( "\nEnter the change in time -> " ); time = input.nextDouble ( ); myballoon.ChangeAlt ( alt, time ); double rate = myballoon.Rate ( ); System.out.println ( "Altitude = " + myballoon.SendAlt ( ) ); System.out.println ( "Time = " + myballoon.SendTime ( ) ); System.out.println ( "Rate of Ascent = " + myballoon.Rate ( ) ); System.out.print ( "\n\nEnter the change in altitude -> " ); alt = input.nextDouble ( ); System.out.print ( "\nEnter the change in time -> " ); time = input.nextDouble ( ); myballoon.ChangeAlt ( alt, time ); rate = myballoon.Rate ( ); System.out.println ( "Altitude = " + myballoon.SendAlt ( ) ); System.out.println ( "Time = " + myballoon.SendTime ( ) ); System.out.println ( "Rate of Ascent = " + myballoon.Rate ( ) ); } }