正答例&実行結果例
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70  | 
						package challenge10; import java.util.Scanner; public class Main { 	public static void main(String[] args) { 		// TODO 自動生成されたメソッド・スタブ 		Vending[] vending = { 				new Vending("コーヒー",150,5), 				new Vending("お茶",110,5), 				new Vending("炭酸飲料",120,5) 		}; 		int total = sale(vending); 		print(vending,total); 	} 	/* 	 * 販売 	 */ 	public static int sale(Vending[] vending) { 	    Scanner scan = new Scanner(System.in); 	    int total=0;			//売上高 		for(;;) { 			//商品表示 			itemPrint(vending); 			//商品選択 			int select = scan.nextInt(); 			//終了なら(99) 			if(select ==  99) { 				break; 			} 			//正当な商品番号が選択されている時処理 			if(select >= 1) { 				if(select <= vending.length) { 					//商品がある時だけ処理 					if( vending[select-1].sale() ) { 						total = total + vending[select-1].getPrice(); 					} 				} 			} 		} 		return total; 	} 	/* 	 * 商品表示 	 */ 	public static void itemPrint(Vending[] vending) { 		//商品情報表示 		for(int i=0;i<vending.length;i=i+1) { 			if( vending[i].getZaiko() !=0 ) { 				System.out.println((i+1)+"."+vending[i].getKind()); 			} 		} 		System.out.println("-------------"); 	} 	/* 	 * 終了表示 	 */ 	public static void  print(Vending[] vending,int total) { 		for(int i=0;i<vending.length;i=i+1) { 			System.out.println((i+1)+"."+vending[i].getKind()+" "+vending[i].getZaiko()+"本"); 		} 		System.out.println("売上:"+total+"円"); 	} }  | 
					
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32  | 
						package challenge10; public class Vending { 	private String kind; 	private int price; 	private int zaiko; 	public Vending(String kind,int price,int zaiko) { 		this.kind = kind; 		this.price = price; 		this.zaiko = zaiko; 	} 	public String getKind() { 		return kind; 	} 	public int getPrice() { 		return price; 	} 	public int getZaiko() { 		return zaiko; 	} 	public boolean sale() { 		if(zaiko >0) { 			//商品を減らす 			zaiko = zaiko - 1; 			return true; 		}else { 			return false; 		} 	} }  | 
					
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41  | 
						1.コーヒー 2.お茶 3.炭酸飲料 ------------- 1 1.コーヒー 2.お茶 3.炭酸飲料 ------------- 1 1.コーヒー 2.お茶 3.炭酸飲料 ------------- 1 1.コーヒー 2.お茶 3.炭酸飲料 ------------- 1 1.コーヒー 2.お茶 3.炭酸飲料 ------------- 1 2.お茶 3.炭酸飲料 ------------- 2 2.お茶 3.炭酸飲料 ------------- 3 2.お茶 3.炭酸飲料 ------------- 99 1.コーヒー 0本 2.お茶 4本 3.炭酸飲料 4本 売上:980円  | 
					

