扫描仪+ TesterClass?

Scanner + TesterClass?

为此,我必须在 Java 中创建一个程序,要求用户输入三角形的所有三个点,然后我必须找到边和面积。所有数学运算都必须与测试人员分开完成 class,我将在其中提示用户问题...
- 我如何要求用户在测试器中输入一些东西 class 但在原始程序中得到这些整数?

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

等等...

并在您创建的函数中传递这些变量。 希望对你有所帮助。

谢谢

在测试器 class 的 main 方法中,您可以创建一个非测试器 class 的实例,其中包含您进行数学运算的函数,即:

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);

在此,您正在创建一个包含所有数学函数和内容的 class 对象,然后在测试器 class 的主要方法中获取输入,然后传递输入到 TriangleMath class (tMath) 实例的 area 函数中。 .charAt(0) 将其转换为 char,而 (int) 将其转换为 int

希望对您有所帮助!