2 Replies - 2424 Views - Last Post: 24 February 2004 - 09:54 PM Rate Topic: -----

#1 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,411
  • Joined: 21-March 01

Algorithm.

Posted 24 February 2004 - 05:04 PM

Quote

You are to assume the role of a secret agent whose mission is to sneak up and drill a small hole in the base of a storage tank that holds a special rocket fuel. The tank is 20 feet high; it is full, and you want it to be empty. The diameter of the tank is 8 feet, and you are going to drill a hole that is only 2 inches in diameter. The velocity of the fuel out the hole is related to the height of the fluid remaining in the tank and is calculated as 8.02 times the square root of the fluid level (in feet) remaining in the tank.

Calculate how long it will take to drain the tank. Display the progress of the program as the simulation passes each 1-minute interval by showing the time and the height of the fluid remaining in the tank. At the end of the simulation, report the total time it took to drain the tank in hours:minutes:seconds format (correct answer: 42 minutes and 45 seconds).

Math things to keep in mind:
[*]Fluid through the hole in an interval is velocity (in feet per second) times area of hole (in square feet), giving a result in cubic feet per second.
[*]If you multiply the velocity by nozzle area, you get cubic feet. Use this to calculate the changing height of fluid in the tank. Then calculate a new velocity.
[*]Remember, radius is one half of a diameter, and volume of a cylinder is pi times radius squared times height. 


That was the question posed to me, and here is the class i created, my math is way wrong. I've screwed around with it for a few days and everything i do is wrong. my teachers are all dumb and can't figure it out either. partly because the wording on the problem is so sketchy.

class DrainTank 
{
  final double PI = 3.141592654;
  
  // instance variables
  private double myHeight = 20;
  private double myLiquid;
  private double myRadius = 4;
  private double myHole = (PI * Math.pow((1/12),2));
  private double myVelocity;
  private double myLiquidInterval = 0;
  private int time = 0;
  private int loop;
  
  // constructor
  DrainTank()
  {
      
  }

  // methods
  void drain()
  {
      myLiquid = (PI*Math.pow(myHole,2)*myHeight);
      do{
          myVelocity = (8.02 * Math.sqrt(myHeight) * (PI / 144));
          //System.out.println("myVelocity: " + myVelocity);
          myLiquidInterval = (myVelocity * Math.pow(myHole,2));
          //System.out.println("myLiquidInterval: " + myLiquidInterval);
          myLiquid = (myLiquid - myLiquidInterval);
          //System.out.println("myLiquid: " + myLiquid);
          myHeight = (myLiquid/(PI * Math.pow(myHole,2)));
          //System.out.println("myHeight: " + myHeight);
          time++;
          if((time % 60)==0)
          {
            loop++;
            System.out.print("Time: " + time + " " + myHeight);
            if((loop%10) == 0) { System.out.println("");}
          }
      }while(myLiquid > 0);
  }
  
}


Is This A Good Question/Topic? 0
  • +

Replies To: Algorithm.

#2 cyberscribe  Icon User is offline

  • humble.genius
  • member icon

Reputation: 10
  • View blog
  • Posts: 1,062
  • Joined: 05-May 02

Re: Algorithm.

Posted 24 February 2004 - 06:38 PM

Alright, Slothie - I want to help you but I don't want to give it away since you're close.

Think about the sequence of events - what happens first, second, third. Think in plain English terms. Then write your loop. If this doesn't crack it open for you, I can give more clues or pseudocode or even some Java if you're really fed up.
Was This Post Helpful? 0
  • +
  • -

#3 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,411
  • Joined: 21-March 01

Re: Algorithm.

Posted 24 February 2004 - 09:54 PM

ok, robert was generous to walk me thru it in instant message and it works great, here's the code for anyone wondering.

import chn.util.*;
import java.text.*;

class DrainTank 
{
    //constants
    final double PI = Math.PI;
    final double hole = PI/144;

    //instance variables
    private double myVol;
    private double myHt;
    private double myVel;
    private int seconds;

    // constructor
    public DrainTank() 
    {
        myVol = 320 * PI;
        myHt = (double)20;
        myVel = 8.02 * Math.sqrt(myHt);
        seconds = 0;
    }

    public void drain() 
    {
        //while there is still fuel in the tank
        while(myVol > 0) {
            myVol -= myVel * hole;//decrement the volume, draining at velocity * hole
            myHt = myVol / (PI * 16);//use the new volume to change the height        
            myVel = 8.02 * Math.sqrt(myHt);//adjust the velocity to the new height
        
            seconds++;//increment the seconds
        
            if( (seconds % 60) == 0)//if seconds represent an even minute, output
                System.out.println(myVol + " @ " + (seconds/60) + ":00");
    
        }  //end while
    
        //now output the minutes and seconds for the total time
        System.out.println("drained @ " + (seconds/60) + ":" + (seconds % 60));
    }
}

//-------------------- End of class --------------------//

public class SpyGame 
{
    public static void main(String[] args)
    {
        DrainTank drill = new DrainTank();    
        drill.drain();
    }
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1