The question is:

Write a Java program that prompts the user to enter six numbers representing the coordinates of P, Q, and R, and displays the following:

1.) Whether P, Q, and R are collinear or represent a triangle;

2.) If P, Q, and R represent a triangle,

(i) the lengths of its sides;

(ii) its circumference and area;

(iii) whether the triangle is a right triangle, and if so, the two nonright angles (in degrees).

P = (Xp, Yp) Q = (Xq, Yq) and R = (Xr, Yr).

Cartesian is one of the few areas in which im utterly lost in, and right now im stumped.

## 6 Replies - 2626 Views - Last Post: 11 September 2011 - 08:37 AM

### #1

# Stumped on a Java Question (cartesian coordinates)

Posted 10 September 2011 - 11:43 PM

##
**Replies To:** Stumped on a Java Question (cartesian coordinates)

### #2

## Re: Stumped on a Java Question (cartesian coordinates)

Posted 10 September 2011 - 11:49 PM

1) If they are collinear, then their slopes will be the same. Remember that slope is (y2 - y1)/(x2 - x1)

2i) The distance formula is d = sqrt((x1 - x2)^2 + (y1 - y2)^2)

2ii) A triangle doesn't have a circumference- a circle does. A triangle has a perimeter though.

2iii) If the Pythagorean theorem holds, then you have a right triangle. From there, you can use basic trig to get the remaining angles. Java's trig methods in the Math class deal with radians, so you will have to convert the results to degrees.

2i) The distance formula is d = sqrt((x1 - x2)^2 + (y1 - y2)^2)

2ii) A triangle doesn't have a circumference- a circle does. A triangle has a perimeter though.

2iii) If the Pythagorean theorem holds, then you have a right triangle. From there, you can use basic trig to get the remaining angles. Java's trig methods in the Math class deal with radians, so you will have to convert the results to degrees.

### #3

## Re: Stumped on a Java Question (cartesian coordinates)

Posted 11 September 2011 - 12:18 AM

absolutely love you mac. i really appreciate it.

Last question is more or less a simple one, but given the need for the user to input 6 numbers in order to determine colliniation and thier distance. thats a simple if then statement right?

That's what I got so far. I really appreciate the help.

Last question is more or less a simple one, but given the need for the user to input 6 numbers in order to determine colliniation and thier distance. thats a simple if then statement right?

publicstaticvoid main(String[] args) { String str; int no,check; try{ BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter 6 numerical values, representing P, Q and R : "); System.out.flush(); str=obj.readLine(); no=Integer.parseInt(str); check=no; for(int i=1;i<=no;i++) { for(int j=check;j>=1;j--) { System.out.print(" "); System.out.flush(); } check=check-1; for(int k=1;k<=i;k++) { System.out.print(" "+i+" "); System.out.flush(); } System.out.println("\n"); } } catch(Exception e) {} } }

That's what I got so far. I really appreciate the help.

This post has been edited by **macosxnerd101**: 11 September 2011 - 08:07 AM

Reason for edit:: Please use code tags

### #4

## Re: Stumped on a Java Question (cartesian coordinates)

Posted 11 September 2011 - 03:32 AM

zerorev9814, on 11 September 2011 - 03:18 AM, said:

Last question is more or less a simple one, but given the need for the user to input 6 numbers in order to determine colliniation and thier distance. thats a simple if then statement right?

You'll want the user to enter 3 points, each with an X and Y component. Not exactly "a simple if then statement," but it's not terribly complicated either. Typically, a Scanner is used to read the keyboard. You can assume the user is predictable (a bad assumption) and simply instruct him/her to enter 6 numbers, or you could provide more prompting to ensure the communication between user and your program is more assured.

### #5

## Re: Stumped on a Java Question (cartesian coordinates)

Posted 11 September 2011 - 03:40 AM

Uhm.

It is a right triangle if the longest side is smaller than the sum of the two other sides

It is a right triangle if the longest side is smaller than the sum of the two other sides

This post has been edited by **CasiOo**: 11 September 2011 - 03:40 AM

### #6

## Re: Stumped on a Java Question (cartesian coordinates)

Posted 11 September 2011 - 06:52 AM

CasiOo, on 11 September 2011 - 06:40 AM, said:

It is a right triangle if the longest side is smaller than the sum of the two other sides

Not sure where you got this. If you just think about a common right triangle, the 3/4/5, imagine increasing the angle between the 3 and 4 sides - the 90-degree angle - just slightly, say to 100. Will the 5 side increase that much so that it is greater than the sum of the other two sides? No. You can verify this with geometric calculators that can be found on the internet by building a triangle with angles 30, 50, and 100, but you don't need to.

If you imagine increasing the angle between the 2 shorter sides, you can see that the longest side will always be shorter than the sum of the other 2. Why? Because it is the shortest distance between two points - a straight line - while the 2 other sides are taking a longer route that includes 2 segments to travel the same distance. This continues until the longest side exactly equals the sum of the other two sides when the angle between the two shorter sides is 180-degrees, making a straight line of the two shorter sides, collapsing into the longer side.

### #7

## Re: Stumped on a Java Question (cartesian coordinates)

Posted 11 September 2011 - 08:37 AM

GregBrannon, on 11 September 2011 - 06:52 AM, said:

CasiOo, on 11 September 2011 - 06:40 AM, said:

It is a right triangle if the longest side is smaller than the sum of the two other sides

Not sure where you got this. If you just think about a common right triangle, the 3/4/5, imagine increasing the angle between the 3 and 4 sides - the 90-degree angle - just slightly, say to 100. Will the 5 side increase that much so that it is greater than the sum of the other two sides? No. You can verify this with geometric calculators that can be found on the internet by building a triangle with angles 30, 50, and 100, but you don't need to.

If you imagine increasing the angle between the 2 shorter sides, you can see that the longest side will always be shorter than the sum of the other 2. Why? Because it is the shortest distance between two points - a straight line - while the 2 other sides are taking a longer route that includes 2 segments to travel the same distance. This continues until the longest side exactly equals the sum of the other two sides when the angle between the two shorter sides is 180-degrees, making a straight line of the two shorter sides, collapsing into the longer side.

Yeah that wasn't what I meant at all. I misunderstood what you guys meant with a 'right triangle', and thought it could just be any kind of triangle. I guess my English fails . But yeah, now I know that a right triangle is a retvinklet triangle in Danish

Page 1 of 1