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

• September 13th, 2011, 03:37 AM
Elle_Le_Belle
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.
• September 13th, 2011, 07:06 AM
newbie
Re: New to Java I am a bit puzzled with my code
Do you have a specific question?
• September 13th, 2011, 09:17 AM
KevinWorkman
Re: New to Java I am a bit puzzled with my code
• September 13th, 2011, 12:54 PM
Jay_20991
Re: New to Java I am a bit puzzled with my code
Quote:

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...:-)
• September 13th, 2011, 01:00 PM
Jay_20991
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...
:-)
• September 13th, 2011, 01:17 PM
Norm
Re: New to Java I am a bit puzzled with my code
Quote:

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?
• September 13th, 2011, 01:50 PM
Elle_Le_Belle
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.
• September 13th, 2011, 02:01 PM
KevinWorkman
Re: New to Java I am a bit puzzled with my code
Missing semicolon?
• September 14th, 2011, 10:11 AM
Jay_20991
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?
• September 14th, 2011, 10:33 AM
KevinWorkman
Re: New to Java I am a bit puzzled with my code
Quote:

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".
• September 15th, 2011, 12:28 PM
AJAXx195
Re: New to Java I am a bit puzzled with my code

(spoonfeeding removed by KevinWorkman)
• September 15th, 2011, 12:52 PM
KevinWorkman
Re: New to Java I am a bit puzzled with my code
Quote:

Originally Posted by AJAXx195