



|
|
P Dunn's Super CS1 Site
|
Programming Challenge Archive
General Problems Solving
Starting Five
|
|
Java Application --
StartingFive
// General Information
// ---------------------------------------------------
// File: StartingFive.java
// Type: java application file
// Date: Fri Sep 15, 2000
// Name: Patrick Dunn
// Line: To find the average height of the new starting l+
ineup
// Application Description
// ---------------------------------------------------
/*
This application determines the average height of the st+
arting
lineup based on the present height of the lineup using G+
oal
Directed Planning.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.math.*;
// Application Class
// ---------------------------------------------------
class StartingFive
{
static public void main (String args[])
{
// set up the variables and constants used in this pro+
gram
double averageHeightPresent = 75.5; // average heigh+
t of the starting lineup
int numPlayers = 5; // number of pla+
yers on the team
double playerOutHeight = 72.0; // the player to+
be subtracted out height
double playerInHeight = 84.0; // the player to+
be added in height
double newAverageHeight; // new average h+
eight placeholder
double presentTotalHeight; // present total+
height
double newTotalHeight; // new total hei+
ght of the team
// display an intro
IO.println();
IO.println("The Starting Five Team");
IO.println("---------------------------------");
IO.println("The average height of the present team: " +
+ averageHeightPresent + " inches");
IO.println("The player's height who is leaving the sta+
rting lineup: "
+ playerOutHeight + " inches");
IO.println("The player's height who is joining the sta+
rting lineup: "
+ playerInHeight + " inches");
// calculate total height of the present team
presentTotalHeight = averageHeightPresent * numPlayers+
;
IO.println("Present total height of the team w / 6 foo+
ter: " +
presentTotalHeight + " inches");
// subtract out 6 foot player
newTotalHeight = presentTotalHeight - playerOutHeight;+
// add in 7 foot player
newTotalHeight = newTotalHeight + playerInHeight;
IO.println("Present total height of the team w / 7 foo+
ter: " +
newTotalHeight + " inches");
// calculate new average height
newAverageHeight = newTotalHeight / numPlayers;
IO.println("New average height of the Starting Five Te+
am: " +
newAverageHeight + " inches");
}
}
// Demo
// ---------------------------------------------------
/*
[patdunn@k6 startingfive]$ javac StartingFive.java
[patdunn@k6 startingfive]$ java StartingFive
The Starting Five Team
---------------------------------
The average height of the present team: 75.5 inches
The player's height who is leaving the starting lineup: 72+
.0 inches
The player's height who is joining the starting lineup: 84+
.0 inches
Present total height of the team w / 6 footer: 377.5 inche+
s
Present total height of the team w / 7 footer: 389.5 inche+
s
New average height of the Starting Five Team: 77.900000000+
000006 inches
[patdunn@k6 startingfive]$
*/
|
|
|