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

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

1. ## 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. ## Re: New to Java I am a bit puzzled with my code

Do you have a specific question?

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

Elle_Le_Belle (September 13th, 2011)

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

Elle_Le_Belle (September 13th, 2011)

6. ## Re: New to Java I am a bit puzzled with my code

Originally Posted by Elle_Le_Belle
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.

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. ## 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. ## 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. ## 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. ## Re: New to Java I am a bit puzzled with my code

Missing semicolon?

14. ## 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. ## Re: New to Java I am a bit puzzled with my code

Originally Posted by Jay_20991
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".

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

copeg (September 14th, 2011)

17. ## Re: New to Java I am a bit puzzled with my code

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

(spoonfeeding removed by KevinWorkman)

18. ## Re: New to Java I am a bit puzzled with my code

Originally Posted by AJAXx195
Here is your Code============>
Read this again: The Problem with Spoon-feeding

Continued attempts at spoonfeeding will cause me to vote to ban you.