CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
Programming Challenge Archive

General Problems Solving
Starting Five
 
The Problem :   The Starting Five.   The average height of the starting five of a particular basketball team is 75.5 inches.   One of these players,  whose height is 6 feet is replaced by a 7 footer.   What is the average height of the new starting lineup?
 
  JavaApplication  -- Starting Five

   // General Information
   // ---------------------------------------------------
  
   // File:  StartingFiveApp.java
   // Type:  java application file
   // Date:  Fri Sep 15, 2000
   // Name:  James W. Bremenour
   // Line:  Height average of a starting line-up
  
   // Application Description
   // ---------------------------------------------------
  
   /*
      Calculates a new average height for the starting 
      five of a basketball team. One player of a certain
      height leaves the line-up, as another player with a
      greater height joins the line-up.
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
  
   // Application Class
   // ---------------------------------------------------
  
      class StartingFiveApp
      {
         static public void main (String args[])
         {
         // Declare the variables
     double originalAverage = 75.5;
     int nrPlayers = 5;
     double oldPlayerHeight = (6.0*12.0);
     double newPlayerHeight = (7.0*12.0);
         // Calculate the new average height
     double newAverage = 
         ((((originalAverage * nrPlayers) 
   - oldPlayerHeight) + newPlayerHeight)
           /5);
         // Display the result
     IO.print ("The new average height is:   ");
     IO.print (newAverage);
     IO.print (" inches");
     IO.println();
         }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
   rocky - bremenou - strtin5 > java StartingFiveApp
   The new average height is:   77.9 inches
   rocky - bremenou - strtin5 > 
   */