Getting the rest of this to work.

Hey earlier today i posted a fragment of this code, but now im down to the completion of the program. I just need some tips on asking the user for system input for two values. Do i have to make two different system.out.prinln inputs for each set of vertex values, or can i do it all in 1 line. im reffering to this line.

String vertex;

System.out.println("Enter the vertex (x, y) as two numbers with a space between them:");

vertex= keyboard.readToken();

This is where the program starts.

import chn.util.*;

class Triangle

{

double computeDistance (int x1,int y1,int x2,int y2)

{

double blah,blah2;

blah= (x1-x2)*(x1-x2);

blah2= (y1-y2)*(y1-y2);

return blah;

}

double computeAngle (double a,double b,double c)

{

double angleA,angleB,angleC,acos;

angleA = ((b*b + c*c - a*a) / 2*(b*c));

angleB = ((a*a + c*c - b*b) / 2*(a*c));

angleC = ((a*a + b*b - c*c) / 2*(a*b));

return angleA;

}

double radianToDegrees (double radians)

{

double rod;

rod=180*radians/ 3.14986736792793420;

return rod;

}

float computeArea (double a,double b,double c)

{

double s,A;

s = 1/2*(a+b+c);

A = s*((s-a)*(s-b)*(s-c));

return A;

}

void triangleOutput (int x1,int y1,int x2,int y2,int x3,int y3,

double a,double b,double c,

double angle1,double angle2,double angle3,double area)

{

}

}

// End of Triangle class

publicclass TriangleStats

{

publicstaticvoid main (String[ ] args)

{

ConsoleIO keyboard =new ConsoleIO();

Triangle myTriangle =new Triangle( );

String vertex;

System.out.println("Enter the vertex (x, y) as two numbers with a space between them:");

vertex= keyboard.readToken();

}

}

[3946 byte] By [Jbinksa] at [2007-10-2 5:39:26]
# 1

> Do i have to make two different system.out.prinln inputs for each set of

> vertex values, or can i do it all in 1 line.

You could do it in one. Be careful though, the user has to enter an int, then a whitespace, another int, and then hit enter. Otherwise, your application will throw an Exception. Here's an example:

String userInput = keyboard.readLine();// read a line from the user

String[] coordinates = userInput.split(" "); // split the line at the point of the whitespace

int x = Integer.parseInt(coordinates[0]);// the first part is the x-coordinate

int y = Integer.parseInt(coordinates[1]);// the second part is the y-coordinate

And maybe you should take another look at the code of your Triangle-class. At least the first method is not correct, and in a lot of methods you're doing nothing with variables you're declaring; in computeAngle for instance: you don't do anything with angleB and angleC...

prometheuzza at 2007-7-16 1:49:46 > top of Java-index,Java Essentials,Java Programming...