Report3
		Day :2003/10/27
		ID  :035740F
		Name:根保光秀
		!!!  This Page Is Made By Shift JIS  !!!


     Report#3:Javaアプリケーションによるオリジナル問題作成と解答例
                多くのJava制御文を用いてオリジナルのJavaアプリケーションによる初級問題を作成し、
                模範解答例を示せ。 



もくじ

1.問題

2.問題出題

3.解答

4.考察

5.感想・反省












  問題のプログラム


○仮想自動販売機

  自動販売機の特徴

           a.1円・5円玉は使えない。
           b.在庫は100缶。
           c.10万円以上は使えない(在庫が100缶なので10万円以上入る事はない)
           
  上の3つの事を破るとエラーが怒ります。またこのような場合にもエラーが怒ります。

    d.購入数入力の時に『0』と入力する。
      e.代金入力の時に1の位が『0』以外。
    f.入力した代金が足りない。


  配列

    配列の中身
        配列の中身は金額とその枚数を表します。具体的には

     abc[][]={{10,1},{100,2},{1000,3},{10000,4}};
                
     この時{10,1}は10が10円を表し1が枚数を表します
     つまり配列abcには10円が1枚,100円が2枚、千円が3枚,一万円が4枚入ってることになります。

            ○Coin
                   販売機内にあるお金の数を表す配列。初期状態では
                   1万円以外は50枚づつ入っている。1万円は0枚

            ○inCoin
                   挿入されたお金の枚数を表す配列。

            ○outCoin
                   おつりの金額を表す配列
     

  変数

            rem   : 入力した数字を格位に分ける時の計算に使う変数。
            inc     :入力した金額が入る変数。
            bno    :購入する数が入る変数。
            price  :合計金額が入る変数。
            oturi  :おつりが入る変数。

  メソッド

    ○Input()
                  購入数や金額を入力する時に使うメソッド。
                  String型の金額をInt型に直してmainに返す。

    ○Omake()
                  買ってくれた人におまけとして
               今日の運勢を占うメソッド。
                  乱数を得てその値によって運勢を三段階で表す。(1星〜3星)
                

-------------------------------------------------------------プログラム---------
/*
 Program  :rep3b.java
 StudentID:035740F
 Author   :Mituhide Neho
 Date     :03/11/09/(Sun)
 Comments :Autmatic Sell Machine Purogram 
*/

 (1)__________

public class rep3b{
    public static void main(String args[]){
        int rem,i=0,inc,bno,price;
        int oturi,rem2;

        int Coin[][]= (2)______________________________
        
        int outCoin[][]={{10,0},{100,0},{1000,0},{10000,0}};
        int inCoin[][]={{10,0},{100,0},{1000,0},{10000,0}};

        System.out.println("\n***Automatic Sell Machine Program***\n");
        System.out.println("Orion Bear is 240yen");
        System.out.print("\nHow many buy?\n input-------> ");

        bno= (3)________
        
        if((bno>100)||(bno<=0)){
            System.out.println("Error!");
            return;
        }
        price=bno*240;
        System.out.println("price="+price+"yen");

        System.out.print("Insert money------->");
        
        inc= (3)_________
        
        if((inc%10!=0)||(inc>=100000)){
            System.out.println("Error!");
            return;
        }
            
        rem=inc;
        do{
            rem=rem/10;
            inCoin[i][1]=inCoin[i][1]+(rem%10);
            Coin[i][1]=Coin[i][1]+inCoin[i][1];
            i++;
        }while(i<4);

        oturi=inc-price;
        if(oturi<=-1){
            System.out.println("Not Enouth Money!\nError!");
        }else if(oturi==0){
            System.out.println("Thank you!\n");
            Omake();
        
        }else if((4)__________){
            
           System.out.println("\nHeres your Change");
            
            i=0;
            rem2=oturi;
            do{
                rem2=rem2/10;
                outCoin[i][1]=outCoin[i][1]+(rem2%10);
                Coin[i][1]=Coin[i][1]-outCoin[i][1];
                i++;
            }while(i<4);
            System.out.println("Oturi="+oturi+"yen\n");
            
            Omake();
        }
    }
    
    static int Input(){

        BufferedReader Reader=
            new BufferedReader(
                               new InputStreamReader(System.in),1);

        String aaa;
        try{
            aaa=Reader.readLine();
            return Integer.parseInt(aaa);
        }catch(Exception e){
            return 0;
        }
    }
    static void Omake(){
        int i,a,b;
        System.out.println("+++Todays Your Luck+++");
        i=(int)(Math.random()*3);
        switch(i){
        case 0:
            System.out.println("  *  ");
            System.out.println("*****");
            System.out.println(" *** ");
            System.out.println("** **");
            break;
        case 1:
            System.out.println("  *     *  ");
            System.out.println("***** *****");
            System.out.println(" ***   *** ");
            System.out.println("** ** ** **");
            break;
        case 2:
            System.out.println("  *     *     *  ");
            System.out.println("***** ***** *****");
            System.out.println(" ***   ***   *** ");
            System.out.println("** ** ** ** ** **");
            break;
        
        (5)_________
            
            System.out.println("Hazure!");
            break;
        }
    }

}




------------------------------------------------実行結果---------
***Automatic Sell Machine Program***

Orion Bear is 240yen

How many buy?
 input-------> 5
price=1200yen
Insert money------->1200
Thank you!

+++Todays Your Luck+++
  *     *     *  
***** ***** *****
 ***   ***   *** 
** ** ** ** ** **


***Automatic Sell Machine Program***

Orion Bear is 240yen

How many buy?
 input-------> 10
price=2400yen
Insert money------->3000

Heres your Change
Oturi=600yen

+++Todays Your Luck+++
  *  
*****
 *** 
** **



--------------------------------------------------------



問題出題





目次へ