Results 1 to 20 of 20
  1. #1
    v1ru5 is offline Member
    Join Date
    Sep 2012
    Posts
    20
    Rep Power
    0

    Default Dirt Track Volume



    Below is what I have completed until now but I am doing a test case and not getting the correct volume. If someone could help me out as to what I am doing wrong here it would be great.

    Java Code:
    import java.util.Scanner;
    
    public class A1Q4
    {   /**
         * Calculate the volume required to cover the track
         */
    
        public static void main( String[] args )
        {
            // SET UP KEYBOARD INPUT 
            Scanner keyboard = new Scanner( System.in );
            // DECLARE VARIABLES/DATA DICTIONARY 
            double rLength = 0;
            double rWidth = 0;
            double tWidth = 0;
            double depth = 0;
            double clayVolume = 0;
             
     
            // Read in the given values
            System.out.print ("Please enter the width of the rectangle part of the inner field in meters: ");
            rWidth = keyboard.nextDouble();
            System.out.print ("Please enter the length of the rectangle part of the inner field in meters: ");
            rLength = keyboard.nextDouble();
            System.out.print ("Please enter the width of the track in meters: ");
            tWidth = keyboard.nextDouble();
            System.out.print ("Please enter the desired depth of clay in centimeters: ");
            depth = keyboard.nextDouble();
            // Call method to compute the volume of clay needed.
            
            clayVolume = findClayVolume (rLength, rWidth, tWidth, depth);
     
            // Diplay the result
            
            System.out.println ("\nThe volume of clay needed to cover the track is " + clayVolume + " cubic metres");
     
        }
    
       /**
        * Description:  include a description of the problem 
        *               solving method (algorithm).
        * Parameters (GIVENS):
        */
    
        private static double findClayVolume(double rLength, double rWidth, double tWidth, double depth)
        {
           // Declaration of the result variable 
          double clayVolume = 0;
           
           // Declaration of the intermediate variables
          double innerTrackVolume = 0;
          double wholeTrackVolume = 0;
          double depthInM = 0;
           
           // Add code for the method 
          // Convert the depth in m
          depthInM = depth/100;
          // Calculate the inner track volume
          innerTrackVolume = (rLength*rWidth*depthInM) + (4/3)*(Math.PI*Math.pow((rWidth/2),3)); //*(rWidth/2)*(rWidth/2));
          // Calculate the whole track volume
          wholeTrackVolume = (rLength*(rWidth + 2*tWidth)*depthInM) + (4/3)*(Math.PI*Math.pow(((rWidth + 2 * tWidth)/2),3)); //*((rWidth + 2 * tWidth)/2)*((rWidth + 2 * tWidth)/2));
          // Calculate the track volume by subtracting whole track from inner track
          clayVolume = wholeTrackVolume - innerTrackVolume;                                                                 
    
           // Return the result
           return clayVolume;
        }
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,549
    Rep Power
    23

    Default Re: Dirt Track Volume

    not getting the correct volume
    Could you post what is on the console including what is entered and the results from the program and add some comments to it saying what the correct volume is?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    v1ru5 is offline Member
    Join Date
    Sep 2012
    Posts
    20
    Rep Power
    0

    Default Re: Dirt Track Volume

    Quote Originally Posted by Norm View Post
    Could you post what is on the console including what is entered and the results from the program and add some comments to it saying what the correct volume is?
    The console output:

    Please enter the width of the rectangle part of the inner field in meters: 300
    Please enter the length of the rectangle part of the inner field in meters: 400
    Please enter the width of the track in meters: 20
    Please enter the desired depth of clay in centimeters: 70

    The volume of clay needed to cover the track is 4842969.501221102 cubic metres

    What the answer should be:

    The volume of clay needed to cover the track is 25274.335088082244 cubic meters

    Thanks for helping me out :)

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,549
    Rep Power
    23

    Default Re: Dirt Track Volume

    Where did you get the correct answer?

    Can you write formulas for computing the surface area for each section of the track?

    If the straight sections were removed and the ends slide together, would the shape be a circle?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    v1ru5 is offline Member
    Join Date
    Sep 2012
    Posts
    20
    Rep Power
    0

    Default Re: Dirt Track Volume

    Yes, if you remove the two straight lines you will get two semicircles which you can combine to form a circle. The formulas were not given, I calculated the area by myself. This is what I did. First, I thought that if I get the volume of the inner track and find the volume of the whole track and do wholeTrackVolume - innerTrackVolume I would get the volume of the track that I want. Below is what I did to find the volume of inner track and whole track.

    Inner Track:

    To find the volume of the inner track I got the volume of the inner rectangle and added it to the volume of the two inner semicircles. So I know the volume of the rectangle is rLength * rWidth * depthInM (I converted depth from cm to m so all units match). To get the volume of the circle, I did (4/3)(PI*r^3). I added the volume of the rectangle and the volume of the circle to get the volume of the inner track.

    Outer track:

    I basically did the same thing except the width of the rectangle was rWidth + 2*tWidth. Also, to get the radius of the circle, instead of dividing rWidth by 2, I had to add tWidth*2 + rWidth then divide by two. When I added the two volumes I got the volume of the outer rectangle.

    Then, as I said before, I did wholeTrackVolume - innerTrackVolume to get the volume that I need.

    Please let me know if something does not make sense, I will try to explain it better.

    Thanks

    Edit: correct answer was given, I did not calculate it.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,549
    Rep Power
    23

    Default Re: Dirt Track Volume

    Are you covering the inner area? Or just the track part that is tWidth wide?

    Can you write the formulas for each section you are computing the area of? Just the formulas.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    v1ru5 is offline Member
    Join Date
    Sep 2012
    Posts
    20
    Rep Power
    0

    Default Re: Dirt Track Volume

    I want to cover just the track part so yes, the part that is tWidth wide. I am not computing area, I am computer volume.

    innerTrackVolume = (rLength*rWidth*depthInM) + (4/3)(PI*((rWidth/2)^3)

    wholeTrackVolume = (rLength*(rWidth+2*tWidth)*depthInM) + (4/3)(PI*((rWidth+(2*tWidth))/2)^3)

    Let me know if you need me to explain anything.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,549
    Rep Power
    23

    Default Re: Dirt Track Volume

    Not sure what you are computing.
    I see the area as the sum of 2 rectangles and the difference between an outer circle and an inner circle.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    v1ru5 is offline Member
    Join Date
    Sep 2012
    Posts
    20
    Rep Power
    0

    Default Re: Dirt Track Volume

    Oh, I just understood what you said. Let me try it out and ill see what happens. Thanks for your help :)

  10. #10
    v1ru5 is offline Member
    Join Date
    Sep 2012
    Posts
    20
    Rep Power
    0

    Default Re: Dirt Track Volume

    Java Code:
    rectangleTrack = (rLength*tWidth*depthInM)*2;
    circleTrack = (4/3)*(Math.PI*Math.pow(((rWidth + (2 * tWidth))/2),3)) - (Math.PI*Math.pow((rWidth/2),3));
    clayVolume = circleTrack + rectangleTrack;
    So, as you suggested I added the two rectangle volumes. Then I took the large circle and subtracted by smaller one. I added the circle and rectangle but I am still getting the same answer so I guess it didn't matter which way I used to get the volume. I guess there is something wrong with my circle track, maybe I am doing something wrong to calculate its volume. Let me know if you find something.

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,549
    Rep Power
    23

    Default Re: Dirt Track Volume

    What is the equation for the area of a circle?
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    v1ru5 is offline Member
    Join Date
    Sep 2012
    Posts
    20
    Rep Power
    0

    Default Re: Dirt Track Volume

    Quote Originally Posted by Norm View Post
    What is the equation for the area of a circle?
    I am not calculating the area, I am calculating the volume.

    (4/3)(PI*r^3) = volume of a circle
    (PI*r^2) = area of a circle

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,549
    Rep Power
    23

    Default Re: Dirt Track Volume

    What shape are you calculating the volume of?

    volume of a circle
    A circle does not have a volume. It is two dimensional. A sphere has a volume. A circle has an area.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    v1ru5 is offline Member
    Join Date
    Sep 2012
    Posts
    20
    Rep Power
    0

    Default Re: Dirt Track Volume

    Quote Originally Posted by Norm View Post
    What shape are you calculating the volume of?


    A circle does not have a volume. It is two dimensional. A sphere has a volume. A circle has an area.
    Yes, sorry. I am calculating the volume of the sphere, not circle.

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,549
    Rep Power
    23

    Default Re: Dirt Track Volume

    I am calculating the volume of the sphere
    Why?
    Have you ever seen or been to a race track? They are basically two dimensional. I've never seen one that looks like a sphere. Maybe for some kind of motorcycle sport.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    v1ru5 is offline Member
    Join Date
    Sep 2012
    Posts
    20
    Rep Power
    0

    Default Re: Dirt Track Volume

    Quote Originally Posted by Norm View Post
    Why?
    Have you ever seen or been to a race track? They are basically two dimensional. I've never seen one that looks like a sphere. Maybe for some kind of motorcycle sport.
    Hmm ya thats true. So I should not use volume of a sphere, I should use area of a circle. Let me try and I will let you know what happens. Thanks!

  17. #17
    v1ru5 is offline Member
    Join Date
    Sep 2012
    Posts
    20
    Rep Power
    0

    Default Re: Dirt Track Volume

    So this is what I did:

    Java Code:
    circleTrack = (Math.PI*Math.pow(((rWidth + (2 * tWidth))/2),2)) - (Math.PI*Math.pow((rWidth/2),2));
    I got a output: The volume of clay needed to cover the track is 31306.192982974666 cubic metres

    That is sort of closer to the expected result but still there is something wrong. Let me know if you find anything else. Thanks for your help.

  18. #18
    larryking923 is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Default Re: Dirt Track Volume

    you are meant to calculate the area of a cylinder..... like you use Pi * (r)^2 * h to find the volume of the semi-circle... if you have any more problems i'll check back.

  19. #19
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,549
    Rep Power
    23

    Default Re: Dirt Track Volume

    @v1ru5
    Break the large expression up into a list of small simple steps that do one thing at a time. Putting it all into ONE expression is both hard to read and understand and makes it harder to debug.

    With that technique ( 7 steps) I got: vol=25274.335088082265
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    v1ru5 is offline Member
    Join Date
    Sep 2012
    Posts
    20
    Rep Power
    0

    Default Re: Dirt Track Volume

    Quote Originally Posted by Norm View Post
    @v1ru5
    Break the large expression up into a list of small simple steps that do one thing at a time. Putting it all into ONE expression is both hard to read and understand and makes it harder to debug.

    With that technique ( 7 steps) I got: vol=25274.335088082265
    Norm and larry, thanks for your help :) I figured the answer out a little earlier but thanks for confirming :) Larry is right tat I am supposed to use PI*r^2 * h. Thanks again!

Similar Threads

  1. Area and Volume help
    By gioeco in forum New To Java
    Replies: 10
    Last Post: 05-13-2012, 04:02 AM
  2. Control volume
    By calippus in forum New To Java
    Replies: 0
    Last Post: 10-31-2011, 02:17 PM
  3. Volume of Intersection
    By afifi in forum Advanced Java
    Replies: 0
    Last Post: 01-07-2011, 10:42 AM
  4. Volume of AudioClip
    By Fedor in forum New To Java
    Replies: 0
    Last Post: 04-25-2009, 04:16 PM
  5. Track download
    By nilesh.malode in forum Advanced Java
    Replies: 1
    Last Post: 07-13-2007, 09:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •