0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Javaで商品購入プログラムを作ってみた

Last updated at Posted at 2024-01-31
public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタ

		System.out.println("注文");
		Scanner scan = new Scanner(System.in);
		String select = scan.next();
		
	Map<String,Integer>list = new HashMap<String,Integer>();
	
	list.put("いちごのケーキ", 100);
	list.put("モンブラン", 200);
	list.put("チョコケーキ", 333);
	list.put("タルト", 234);
	list.put("チーズケーキ", 123);
	
	int total = 0;
	
	switch(select) {
	 case "いちごのケーキ":
	    case "モンブラン":
	    case "チョコケーキ":
	    case "タルト":
	    case "チーズケーキ":
	    	System.out.println("購入個数を選んでください");
	    	int quantity = scan.nextInt();
	    	if(list.containsKey(select)) {
	    		int price =list.get(select);
	    		double subTotal = (price*1.10) * quantity;
	    		total = (int)subTotal;
	    	}else {
	    		System.out.println("その商品は扱っていません");
	    	}
	    	break;
	    	
	
	}
	System.out.println("合計金額は"+total+"円です");
	scan.close();
	

	}

}
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?