一直把我的头撞到墙上,这可能是一个我不太明白的简单问题。我有这三个类,试图在它们之间传递对象/方法。
这是第一堂课
public class LargeMapDriver
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int value1;
ThyPoint p1 = new ThyPoint(132, 734);
ThyPoint p2 = new ThyPoint(56, 998);
ThyPoint p3 = new ThyPoint(100, 105);
System.out.println("Enter value: ");
order = keyboard.nextInt();
LargeMap myMap = new LargeMap(value1, p1, p2, p3);
其次,指针类。
public class ThyPoint
{
private int a;
private int b;
//constructor
public ThyPoint(int x, int y)
{
a = x;
b = y;
}
//...
//set and get methods for a and b... not shown
//...
public String toString()
{
return "a: " + getValueA() + " b: " + getValueA();
}
}
最后一个类,一个显示构造函数错误。
public class LargeMap
{
//GETTING CONSTRUCTOR(s) ERROR
public static void goodMethod(int value1, ThyPoint p1, ThyPoint p2, ThyPoint p3)
{
if ( value1 == 0 )
System.out.println( p1.toString() + p2.toString() + p3.toString());
else
System.out.println( p2.toString() + p3.toString() + p1.toString());
}
}
好的,所以问题出现了:
**constructor LargeMap in class LargeMap cannot be applied to given types;
LargeMap myMap = new LargeMap(value1, p1, p2, p3);
^
required: no arguments
found int,ThyPoint,ThyPoint,ThyPoint
reason: actual and formal arguments differ in length**
所以,我试图为 LargeMap 类创建一个构造函数,但失败了,我试图将 p1、p2、p3 对象中的这些值传递给构造函数以接受。并初始化它们中的值,我该怎么做?我想在其中初始化的值是:
ThyPoint p1 = new ThyPoint(132, 734);
ThyPoint p2 = new ThyPoint(56, 998);
ThyPoint p3 = new ThyPoint(100, 105);
此外,LargeMap 类必须保持无效。不过,它不必是静态的或公开的。