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.

Results 1 to 12 of 12

Thread: New to Java I am a bit puzzled with my code

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default New to Java I am a bit puzzled with my code

    Hello Everyone!
    I am new to Java and this site as well, I am in a computer science course at my university and we are being asked to solve math problems. I know my code is not correct, however our professor was not too clear on how to write it.. this is what I have so far

    import java.awt.Point;
    public class AvogtA03 {

    public static void main (String[] args) {

    double X1 = 7;
    double X2 = 0;
    double y1 = 28;
    double y2 = 28;



    double distanceOne = Math.sqrt(((X2-X1)*(X2-X1))+((y2-y1)*(y2-y1)));
    double slopeOne = (y2-y1) / (X2-X1)



    System.out.println("Distance One = " + distanceOne) ;
    System.out.println("Slope One = " + slopeOne) ;

    }
    }

    I am solving for distance and slope of two points, If you do give me the answer to correcting my code please explain why so I could take note for future reference. Thank you so much for all of your help.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: New to Java I am a bit puzzled with my code

    Do you have a specific question?
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. The Following User Says Thank You to newbie For This Useful Post:

    Elle_Le_Belle (September 13th, 2011)

  4. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: New to Java I am a bit puzzled with my code

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. The Following User Says Thank You to KevinWorkman For This Useful Post:

    Elle_Le_Belle (September 13th, 2011)

  6. #4
    Junior Member
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: New to Java I am a bit puzzled with my code

    Quote Originally Posted by Elle_Le_Belle View Post
    Hello Everyone!
    I am new to Java and this site as well, I am in a computer science course at my university and we are being asked to solve math problems. I know my code is not correct, however our professor was not too clear on how to write it.. this is what I have so far

    import java.awt.Point;
    public class AvogtA03 {

    public static void main (String[] args) {

    double X1 = 7;
    double X2 = 0;
    double y1 = 28;
    double y2 = 28;



    double distanceOne = Math.sqrt(((X2-X1)*(X2-X1))+((y2-y1)*(y2-y1)));
    double slopeOne = (y2-y1) / (X2-X1)



    System.out.println("Distance One = " + distanceOne) ;
    System.out.println("Slope One = " + slopeOne) ;

    }
    }

    I am solving for distance and slope of two points, If you do give me the answer to correcting my code please explain why so I could take note for future reference. Thank you so much for all of your help.

    Answer:
    first of all the variables should not start with capital letters...(X1,X2)..and try with (x1-x2) and (y1-y2) instead of (x2-x1) and (y2-y1) respectively..all d best...and please let me know if my answer has any worth for you.. Jay...:-)

  7. The Following User Says Thank You to Jay_20991 For This Useful Post:

    Elle_Le_Belle (September 13th, 2011)

  8. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: New to Java I am a bit puzzled with my code

    First of all the variables should not start with capital letters...(X1,X2)..and try with (x1-x2) and (y1-y2) instead of (x2-x1) and (y2-y1) respectively..all d best...and please let me know if my answer has any worth for you.. Jay...
    :-)

  9. The Following User Says Thank You to Jay_20991 For This Useful Post:

    Elle_Le_Belle (September 13th, 2011)

  10. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: New to Java I am a bit puzzled with my code

    I am solving for distance and slope of two points,
    Can you solve the problem manually or with a calculator?
    What are the steps you need to do to solve the problem?

  11. The Following User Says Thank You to Norm For This Useful Post:

    Elle_Le_Belle (September 13th, 2011)

  12. #7
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: New to Java I am a bit puzzled with my code

    I know how to conduct the problem manually just fine, but the point of the class is to learn how to make a program that runs it every time I compile in JGRASP I recieve the following message

    AvogtA03.java:14: error: unexpected type
    double slopeOne = (y2-y1) / (x2-x1)
    ^
    required: class
    found: value
    1 error

    and I cannot distinguish the proper way to solve it. So I guess that is my main problem.

    Thank you so much by the way for the help (: It means alot.

  13. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: New to Java I am a bit puzzled with my code

    Missing semicolon?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  14. #9
    Junior Member
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: New to Java I am a bit puzzled with my code

    i m again telling you dat try wid (x1-x2) n (y1-y2) instead of (x2-x1) n (y2-y1)...it will be more suitable for ur particular question...n equation will remain same in both the ways..so just try dat...ok?

  15. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: New to Java I am a bit puzzled with my code

    Quote Originally Posted by Jay_20991 View Post
    i m again telling you dat try wid (x1-x2) n (y1-y2) instead of (x2-x1) n (y2-y1)...it will be more suitable for ur particular question...n equation will remain same in both the ways..so just try dat...ok?
    Wtf? The order of the values does not matter as long as they are consistent.

    And please try to use proper spelling and grammar. Many of our users have a non-English first language, so it can be pretty difficult to translate words like "ur" or "dat" or "wid".
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  16. The Following User Says Thank You to KevinWorkman For This Useful Post:

    copeg (September 14th, 2011)

  17. #11
    Junior Member
    Join Date
    Aug 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: New to Java I am a bit puzzled with my code

    Here is your Code============>

    (spoonfeeding removed by KevinWorkman)
    Last edited by KevinWorkman; September 15th, 2011 at 11:51 AM. Reason: removed spoonfeeding

  18. #12
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: New to Java I am a bit puzzled with my code

    Quote Originally Posted by AJAXx195 View Post
    Here is your Code============>
    Read this again: http://www.javaprogrammingforums.com...n-feeding.html

    Continued attempts at spoonfeeding will cause me to vote to ban you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java files compilation with java code
    By stallapp in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: July 14th, 2011, 08:12 AM
  2. Replies: 10
    Last Post: April 5th, 2011, 09:09 AM
  3. Need java code help
    By Gradybaby16 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 19th, 2010, 10:54 AM
  4. Replies: 2
    Last Post: August 1st, 2010, 06:29 AM
  5. Convert Java Program to Java ME code
    By rinchan11 in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: October 5th, 2009, 10:18 PM