0

おそらく単純な問題で、よくわからない問題で頭を壁にぶつけていました。これら3つのクラスがあり、それらの間でオブジェクト/メソッドを渡そうとしています。

ファーストクラスはこちら

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 は無効のままにする必要があります。ただし、静的またはパブリックである必要はありません。

4

3 に答える 3