2016-09-13 9 views
1

これは私の割り当ての説明ですが、toStreamを使用しようとしていません。私は答えが欲しいのではなく、問題点を指導し、JavaでPointクラスを使用しています。君たちありがとう!toStringを使用して座標をプロットしよう

"プレーンp1とp2の2つの点それぞれを表すx1、y1、x2、y2の4つの整数値を求めるプロンプトJavaクラスライブラリのPointクラスを使用するオブジェクトp1とp2を入力データでポイントし、そのtoStringメソッドを使って両方のPointオブジェクトのデータを出力します。

import java.util.Scanner; 
public class Point { 


    public static void main(String[] args) { 
    Scanner keyboard = new Scanner(System.in); 
    int x1, x2, y1, y2; 

    System.out.println("Please enter your first X coordinate!"); 
    x1 = keyboard.nextInt(); 
    System.out.println("Please enter your second X coordinate!"); 
    x2 = keyboard.nextInt(); 
    System.out.println("Please enter your first Y coordinate!"); 
    y1 = keyboard.nextInt(); 
    System.out.println("Please enter your second Y coordinate!"); 
    y2 = keyboard.nextInt(); 

Point p1 = new Point(); 
Point p2 = new Point(); 

p1.toStream(x1,y1); 
    } 



} 
+1

あなたは 'toString'または' toStream'を使用するようにしたいですか? – sidgate

答えて

2

あなたはそれらに価値を与え、その後、単にtoString、ないtoStreamを使用してそれらをプリントアウトするポイントオブジェクトを初期化する必要があります。

以下は、必要な作業に適したコードなので、自分で試してみたい場合は、ここで読んでください。


int x1, y1, x2, y2; 

... 

Point p1 = new Point(x1, y1), p2 = new Point(x2, y2); 
System.out.println(p1); 
System.out.println(p2); // You could use p1.toString() and p2.toString() here instead, but the println(Object o) already calls #toString() on the object. 
+0

これまでのご協力ありがとうございます!コンパイルするときにこのエラーが出ます。 ERROR:コンストラクタPointクラスのPointは、指定された型には適用できません。 必須:引数なし found:int、int –

+0

intをポイントコンストラクタに渡してもよろしいですか? – Deximus

関連する問題