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 2 of 2 FirstFirst 12
Results 26 to 37 of 37

Thread: Physics Program

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

    Default Re: Physics Program

    What is the error.

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

    Default Re: Physics Program

    ';' expected. thats all it says

  3. #28
    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));
    }
    }

    I missed a colon at "Scanner read=new Scanner(System.in)"

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

    Default Re: Physics Program

    now there is an error with the return first * second. it says "possible loss of precision"

  5. #30
    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 double 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));
    }
    }

    Sorry for all those bugs. Im not in front of my ide . Ok try this.

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

    Default Re: Physics Program

    now for Scanner read=new Scanner(System.in); it says cannot find symbol - class Scanner. I'm really sorry for bothering you with all this. You are a really great guy for helping me this much. I hope you know that and I really appreciate it.

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

    Default Re: Physics Program

    Did you import?

    import java.util.*;

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

    Default Re: Physics Program

    no. do i put that right before the code?

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

    Default Re: Physics Program

    yes. Hope it works.

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

    Default Re: Physics Program

    that work but now it says cannot find symbol - method CalculateForce(double,double) for system.out.println("The Force is " + formula.CaclulateForce(a,b));

  11. #36
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Physics Program

    formula.CaclulateForce(a,b));

    Typo should be

    formula.CalculateForce(a,b));

  12. #37
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Physics Program

    import java.util.Scanner;
     
    public class Force{
     
    public double CalculateForce(double first, double second){
    return first * second;
    }
     
    public static void main(String args[])
    {    
        double mass = 0;
        double acceleration = 0;
     
        Force formula = new Force();
        Scanner read = new Scanner(System.in);
     
        System.out.println("Enter Mass: ");
        mass = read.nextDouble();
     
        System.out.println("Enter Acceleration: ");
        acceleration = read.nextDouble();
     
        System.out.println("The Force is " + formula.CalculateForce(mass,acceleration));
    }
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Page 2 of 2 FirstFirst 12