Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 37

Thread: Physics Program

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Physics Program

    i need a simple physics formula. F=ma. Please create a program that has you input the mass and the acceleration and return the force. PLEASE i need this by monday. If you can please answer my other thread i need that too. Also add comments to each line of code about what it does with a // and then the cod. Much aprecciated.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: Physics Program

    Scanner sin = new Scanner(System.in);
    double m = sin.nextDouble();
    double a = sin.nextDouble();
     
    System.out.println("F = " + (m*a) );
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  3. #3
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Re: Physics Program

    thank you but i also need the code for the prompts to enter the numbers for mass and acceleration. thank you in avdance.

  4. #4
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: Physics Program

    You are honestly telling me you can't do that. The information is there, and it would have been the first thing you were taught on your course. I have no problem helping people, but you are showing you have done no work at all, and quite frankly I don't want a bunch of retards walking around with Qualifications they don't know a thing about.

    Regards,
    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  5. #5
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Re: Physics Program

    Haha, I love how you ended that with Regards. Anyway, I know how to do it i just want to make sure that i get it right. If i put up the code would you help me with my mistakes?

  6. #6
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: Physics Program

    Ye I don't have a problem with that.
    I never mind helping.

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  7. #7
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Physics Program

    public static [B]Force[/B] readInput()
    {
    Double a,b,c;
    System.out.println("Please input mass.);
    a=SavitchIn.readLineDouble();
    System.out.println("Please input acceleration");
    Force f = new Force(a,b);
    return f;
    }

    How's that? It's a start right.

  8. #8
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Physics Program

    aww forgot the savitch.in for the second input sorry.

  9. #9
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: Physics Program

    What is savitchIn defined as? (post all your code) that way I can see your Force class too.

    You can edit your posts too, and please you code tags [ code ] [ /code ] ( without spaces )

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  10. #10
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Physics Program

    savitch.In is the java code that can be exchaged for something else. I use Blujay and my computer is pregrammed to accept savitch.In i do not know the exact word. And about the class, that's where i get iffi. Send me a random class and i can make it into the Force class but I'm not sure how to exactly construct a class. I'm really sorry. I have tried but none of the stuff i learn seems to stick.

  11. #11
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: Physics Program

    class Force{
         public Force(double a, double b){
              // some code here
         }
    }//end of class

    Theres a basic class called force, with a constructor to match your call...
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  12. #12
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Physics Program

    class Force{
         public Force(double a, double b){
              public int mass;
              public int acceleration;//is that right?
         }
    }//end of class

  13. #13
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: Physics Program

    You can't have global variables defined within a function

    class Force{
         public int mass;
         public int acceleration;//is that right?
         public Force(double a, double b){
     
         }
    }//end of class
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  14. #14
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Physics Program

    "you can't have global variables defined within a function"

    yeah i totally understood what that meant So is that all the code. I just put that all together and thats my code?

  15. #15
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: Physics Program

    No farm from it, but I'm very confused as to what you are trying to achieve and how you are trying to d it

    Chris
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  16. #16
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Physics Program

    i simply want a program in which it prompts you to enter the mass and the acceleration and then it returns the force. what is hard to understand about that?

  17. #17
    Member Fendaril's Avatar
    Join Date
    Nov 2008
    Posts
    54
    Thanks
    7
    Thanked 6 Times in 5 Posts

    Default Re: Physics Program

    I think Chris is confused as to how you want to go about achieving this.

  18. #18
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Physics Program

    i just want him to put the code that is required to do the formula for F=ma. If you can please do it and notate it. This is my final project for programming class and i have just barely been getting by. I know now that I am not meant to be a programmer I want to be an Engineer but I aslo want to pass this class. So please just write the code and write what each line does.

  19. #19
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Physics Program

    public class Force extends Object
    {
    private double mass;
    private double accel;
    private double force;
    public [B]Force[/B]
    {
        mass=0;
        accel=0;
        force=1;
    }
    public [B]Force[/B]e(double a, double b)
    {
        mass=a;
        accel=b;
        force=1;
    }
    public static [B]Force[/B] readInput()
    {
        double a,b;
      public static Force readInput()
    {
    Double a,b,c;
    System.out.println("Please input mass.);
    a=SavitchIn.readLineDouble();
    System.out.println("Please input acceleration");
    b=SavitchIn.readLineDouble();
    Force f = new [B]Force[/B](a,b);
    return f;
    }
     
    public void [B]showData[/B]()
    {
        System.out.[B]println[/B]("The force is "+force);
    }

  20. #20
    Member Fendaril's Avatar
    Join Date
    Nov 2008
    Posts
    54
    Thanks
    7
    Thanked 6 Times in 5 Posts

    Default Re: Physics Program

    Class Force
    {
    Public int CalculateForce(double first, double second)
    {
    return first * second
    }
    Public Static void main(String args[])
    {
    Force formula=new Force();
    Scanner read=new Scanner(System.in)
    double a=0
    double b=0
    a=read.nextDouble();
    b=read.nextDouble();
    system.out.println("The Force is " + formula.CaclulateForce(a,b));
    }
    }

    Im not cut out to be a programmer either. Actually nobody is. It just depends on how much effort you put in. Study outside of class.

    your above code included alot of uneccessary stuff. This is the simplest most straightforward solution.
    Last edited by Fendaril; June 14th, 2009 at 10:57 PM.

  21. The Following User Says Thank You to Fendaril For This Useful Post:

    pwngrammer (June 14th, 2009)

  22. #21
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Physics Program

    Thank You! Is that everything. I have tried studying out of class but the website feel so cluttered and its hard to understand but I'll keep trying. I greatly appreciate this!

  23. #22
    Member Fendaril's Avatar
    Join Date
    Nov 2008
    Posts
    54
    Thanks
    7
    Thanked 6 Times in 5 Posts

    Default Re: Physics Program

    That is everything.

  24. #23
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Physics Program

    Sorry to bother again but when i try to compile it stops me at double a=0 and it says ";" expected so i added the semicolon but it still says the same thing. any ideas.

  25. #24
    Member Fendaril's Avatar
    Join Date
    Nov 2008
    Posts
    54
    Thanks
    7
    Thanked 6 Times in 5 Posts

    Default Re: Physics Program

    Class Force
    {
    Public int CalculateForce(double first, double second)
    {
    return first * second;
    }
    Public Static void main(String args[])
    {
    Force formula=new Force();
    Scanner read=new Scanner(System.in)
    double a=0;
    double b=0;
    a=read.nextDouble();
    b=read.nextDouble();
    system.out.println("The Force is " + formula.CaclulateForce(a,b));
    }
    }

    here ya go. Sorry its late and I forgot the semi-colons.

  26. #25
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Physics Program

    it still wont work the semi colon is there but it doesnt work

Page 1 of 2 12 LastLast