**講義用スライド [#w3f2486b]
#ref(./第6_5回.pdf);

**Tips [#l8a470d5]
-カレントディレクトリを右クリックで指定して、コマンドプロンプトを簡単便利に起動する@情報科学屋さんを目指す人のメモ ~
http://did2.blog64.fc2.com/blog-entry-245.html

**基礎クラス用演習問題 [#ba900530]
解答は

&size(20){ホスト名: earth.mlab.im.dendai.ac.jp};

&size(20){ディレクトリ: /home/submit/JavaBeginners/[今日の日付]/[学籍番号]};

に提出しなさい。ソースファイル (〜.java) のみを提出。
提出は gFTP 等の ftp ソフトを用いて行うこと。

&size(20){''提出先が木曜日と異なることに注意''};

***問題1(Beginners') [#zda44acc]
[[10月17日>../2011年10月17日]]に作成したVector2Dクラスに,自身をマイナスベクトルとするNegativeメソッドを追加しなさい.

プログラム名はVectorNegativeとする.

 class Vector2D
 {
     double x;
     double y;
     
     double GetX()
     {
         return x;
     }
     
     double GetY()
     {
         return y;
     }
     
     void SetValue(double newx, double newy)
     {
         x = newx;
         y = newy;
     }
     
     void Print()
     {
         System.out.print("(" + x + ", " + y + ")");
     }
     
     String ToString()
     {
         return "(" + x + ", " + y + ")";
     }
 
    double GetLength()
    {
        return Math.sqrt(x * x + y * y);
    }
    
    void Normalize()
    {
        double l = GetLength();
        x /= l;
        y /= l;
    }
     
     //TO DO:
     //自身をマイナスベクトルとするメソッドNegativeを作成する
 }
 
 public class VectorNegative
 {  
 	static public void main(String[] args)
 	{
 		if (args.length != 2)
 		{
 			System.out.println("引数を2つ指定してください");
 			return;
 		}
 		
 		//TO DO:
  		//Vector2D型の変数を作る
                  //インスタンスを作る
                  //コマンドライン引数1番目をx,2番目をyとしてベクトルに値をセットする
                  //Negativeメソッドを使用してベクトルをマイナスベクトルとする
                  //結果を画面に表示する
	 }
 }

実行例(表示方法は各自変更して良い):
 >java VectorNegative 1.0 2.0
 v=(-1.0, -2.0)

***問題2(Beginners') [#f875286d]
[[10月17日>../2011年10月17日]]に作成したVector2Dクラスに,double型の引数sを受け取り,自身をs倍(スケーリング)するScalingメソッドを追加しなさい.

プログラム名はVectorScalingとする.

 class Vector2D
 {
     double x;
     double y;
     
     double GetX()
     {
         return x;
     }
     
     double GetY()
     {
         return y;
     }
     
     void SetValue(double newx, double newy)
     {
         x = newx;
         y = newy;
     }
     
     void Print()
     {
         System.out.print("(" + x + ", " + y + ")");
     }
     
     String ToString()
     {
         return "(" + x + ", " + y + ")";
     }
     
    double GetLength()
    {
        return Math.sqrt(x * x + y * y);
    }
    
    void Normalize()
    {
        double l = GetLength();
        x /= l;
        y /= l;
    }
 
    //Negativeメソッド
 
    //TO DO:
    //double型の引数sを受け取り,自身をs倍(スケーリング)する
    //Scalingメソッドを作る
 }  
 
 public class VectorScaling
 {  
 	static public void main(String[] args)
 	{
 		if (args.length != 2)
 		if (args.length != 3)
 		{
 			System.out.println("引数を2つ指定してください");
 			System.out.println("引数を3つ指定してください");
 			return;
 		}
 		
 		//TO DO:
 		//Vector2D型の変数を作る
                  //インスタンスを作る
                  //コマンドライン引数1番目をx,2番目をyとしてベクトルに値をセットする
                  //コマンドライン引数3番目の値をsとして,Scalingメソッドを使用しベクトルをs倍する
                  //結果を表示する         
	 }
 } 

実行例(表示方法は各自変更して良い):
 >java VectorScaling 1.0 1.0 5.0
 v=(5.0, 5.0)



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS