-3

So for this I have to create a program in Java that asks the user to input all three points of a triangle, and then I must find the sides and area. All the math must be done separately from the tester class, where I will prompt the user with the questions...
- how do I ask the user to input something in the tester class but get those integers back in the original program?

Nosferatu
  • 3
  • 1

2 Answers2

0
Scanner s = new Scanner();
double x1 = s.nextDouble();
double y1 = s.nextDouble();

and so on...

and pass those variables in the functions that you have created. I hope it will help you.

Thanks

Rahul
  • 130
  • 2
0

In the tester class's main method, you can make an instance of the non-tester class containing the functions where you do the math, i.e.:

TriangleMath tMath = new TriangleMath();
// where TriangleMath is the name of the other class, and "tMath" is
// an instance of it. then:

Scanner keyboard = new Scanner(System.in);
int point1 = (int) keyboard.nextLine().charAt(0);
int point2 = (int) keyboard.nextLine().charAt(0);
int point3 = (int) keyboard.nextLine().charAt(0);
int area = tMath.area(point1, point2, point3);

in this, you're making an object of the class containing all of the math functions and stuff, then getting the input in the main method of the tester class, then passing the inputs into the area function of the instance of the TriangleMath class (tMath). The .charAt(0) turns it into a char, and the (int) casts it as an int.

I hope I was of some help!

Cactus
  • 27,075
  • 9
  • 69
  • 149
Melody
  • 41
  • 3