第四章選擇結構練習題4

Duanhaifeng55發表於2018-03-29

//換購活動練習題

package learn;

import java.util.Scanner;
public class Redemption {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("請輸入消費金額:");
int money = input.nextInt();
if (money >= 50) {
System.out.println("是否參加優惠換購活動:");
System.out.println("1:滿50元,加2元換購百事可樂飲料一瓶");
System.out.println("2:滿100元,加3元換購500ml可樂一瓶");
System.out.println("3:滿100元,加10元換購5KG麵粉");
System.out.println("4:滿200,加10元換購蘇泊爾炒菜鍋1個");
System.out.println("5:滿200元,加20元換購歐萊雅爽膚水一瓶");
System.out.println("0:不換購");
System.out.println("請選擇:");
int xuanze = input.nextInt();
switch (xuanze) {
case 1:
System.out.println("成功換購百事可樂一瓶");
System.out.print("本次消費金額:" + (money + 2));
break;
case 2:
if(money>=100) {
System.out.println("成功換購500ml可樂一瓶");
System.out.print("本次消費金額:" + (money + 3));
}else {System.out.println("不好意思您不能換購此商品");}
break;
case 3:
if(money>=100) {
System.out.println("成功換購5KG麵粉");
System.out.print("本次消費金額:" + (money + 10));
}else {System.out.println("不好意思您不能換購此商品");}
break;
case 4:
if(money>=200) {
System.out.println("成功換購1個蘇泊爾炒菜鍋");
System.out.print("本次消費金額:" + (money + 10));
}else {System.out.println("不好意思您不能換購此商品");}
break;
case 5:
if(money>=200) {
System.out.println("成功換購歐萊雅爽膚水一瓶");
System.out.print("本次消費金額:" + (money + 20));
}else {System.out.println("不好意思您不能換購此商品");}
break;
case 0:
System.out.println("謝謝您的光臨!");
System.out.print("本次消費金額:" + money);
break;
default:
System.out.println("輸入錯誤請重新輸入");
}
} else {
System.out.println("抱歉,您無法參加此活動");
System.out.println("本次消費總金額:" + money);
}

}
}

相關文章