0

I need to Create a “main” class called “ParticleDropClass”. The purpose of this class is to contain a calculation of the time it takes for a massive body to fall to the bottom of a vessel containing a viscous liquid.

public class ParticleDropClass {
    double m;
    double d;
    double z;
    double t;
    double v;

    public ParticleDropClass (double x, double y){x=m;y=d;} // creating a constructor 

    public  final double g= 9.81 ;//constants
    public final double  h = 10.0;//constants

    public void drop(double dt ){
        t=0;v=0;
        double  z=h;// intial height at 10m
        while ( z>= 0.0){
            double  a= (d*v*v)/m-g;// formula for body's acceleration
            double dv= a*dt;
            double dz=v*dt ;
            double z1= z+dz;
            double v1= v+dv;
            double t1=t+dt;
            t1=t;
            v1=v;
            z1=z;
        }

        System.out.println("t ="+t +"dt="+t+"s"+ "\n"+"final v="+v+"m/s" );
    }

    public static void main(String[] args) {
        double m=4.3;double d=2.5 ;
        ParticleDropClass b= new ParticleDropClass(m,d);// for an object of               mass 4.3 and 2.5 , at height 0.5 I create a object .
        b.drop(0.5);
    }
}

But I run the above code nothing happens, why?

2
  • i dont think the output is actually in the function Commented Aug 8, 2013 at 17:35
  • Also, after everything else I've seen in the answers, you might still get bitten by floating point issues. Commented Aug 8, 2013 at 17:42

5 Answers 5

2

You have an infinite loop in drop because the value of z never changes. On a side note I suggest that you fix your indentation and line breaking. It's easily fixed using an IDE such as Eclipse.

I think you meant to write:

z = z1;
t = t1;
v = v1;

and, in the construtor:

m = x;
d = y;

The left operand gets the value of the right operand.

Sign up to request clarification or add additional context in comments.

2 Comments

@RobinPhilip See my edit. It might clear things up. You're assigning values in an incorrect way.
@RobinPhilip And z++ wouldn't work since you want z to decrease :), maybe z--.
1

There are two problems:

In the constructor, you aren't setting m and d, instead, you're setting x and y, which does nothing.

Also, in your while loop, you are not updating the values of t, v and z. Instead, you are just setting your temporary values back to the original.

Comments

1
while ( z>= 0.0)

This is the problem. Your while loop is never altering the variable z, so the loop never ends and never reaches your print statement.

Comments

1
     public ParticleDropClass (double x, double y){
       x=m;
       y=d;
      }

this is the obvious problem. this does nothing but make x and y 0. May be there are more.

edit

As others have pointed out already, there's an infinite loop in drop.

1 Comment

b.drop(0.5) calls the function drop(int) from the main
0

Looks like you're in an infinite loop. You z (which you're setting to h which is 10) is always greater than or equal to 0.0. You should use better indentation and since I'm pretty sure you're a student, think about using more meaningful identifiers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.