



|
|
My Intro to Object-Oriented Programming
|
Programming Challenge Archive
Programming Assignment # 1
Starting Five
|
|
|
The average height of the starting five on a basketball team is given. When one 6 ' player is replaced with a 7 ' player, find the revised height of the new starting five. The current average height is 75.5 inches.
JavaApplication - Programming Assignment # 1 --
The Starting Five
// General Information
// ---------------------------------------------------
// File: TheStartingFiveApp.java
// Type: java application file
// Date: Sat Sep 16, 2000
// Name: Jeffrey R. Norkoli
// Line: Find average height of basketball team's
// starting lineup.
// Application Description
// ---------------------------------------------------
/*
The average height of the starting five on a
basketball team is given. When one 6' player is
replaced with a 7' player, find the revised height
of the new starting five. The current average
height is 75.5 inches.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.math.*;
// Application Class
// ---------------------------------------------------
class TheStartingFiveApp
{
static public void main (String args[])
{
// With the 6' player removed from the
// lineup, determine the average height
// of the remaining players.
double aveHeightTeam = 75.5;
double numPlayersOnTeam = 5.0;
double numPlayersRemaining = 4.0;
double heightOfSixFooter = 72.0;
double aveHeightPlayersRemaining =
((aveHeightTeam * numPlayersOnTeam)
- heightOfSixFooter) / numPlayersRemaining;
// Compute new average height by adding the 7' player
// to the lineup.
double heightOfSevenFooter = 84.0;
double newAveHeightTeam = ((aveHeightPlayersRemaining
* numPlayersRemaining) + heightOfSevenFooter)
/ numPlayersOnTeam;
// Display result.
IO.print ("The average height of the starting
five is ");
IO.print (newAveHeightTeam);
IO.println (" inches.");
}
}
// Demo
// ---------------------------------------------------
/*
$ javac TheStartingFiveApp.java
$ java TheStartingFiveApp
The average height of the starting five is 77.9 inches.
$
*/
|
|
|