淡旺季機票的價格問題(switch語句與if-else語句嵌套)


項目背景
 淡旺季機票的價格,原價機票價格為5000元,
 淡季頭等艙打5折,經濟艙打4折 
 旺季頭等艙打9折,經濟艙打8折
  
 要求 編寫程序實現: 輸入任意的月份與艙位來計算機票的價格
 1代表頭等艙,2代表經濟艙 4-10月為旺季,其他月份為淡季


package
com.summer.cn; import java.util.Scanner; /** * @author Summer * 淡旺季機票的價格,原價機票價格為5000元, * 淡季頭等艙打5折,經濟艙打4折 * 旺季頭等艙打9折,經濟艙打8折 * * 要求 編寫程序實現: 輸入任意的月份與艙位來計算機票的價格 * 1代表頭等艙,2代表經濟艙 4-10月為旺季,其他月份為淡季 */ public class Test041513 { public static void main(String[] args) { //輸入原票價,同時錄入乘坐的艙型和月份,並獲取錄入的數據 double price = 5000; Scanner sc = new Scanner(System.in); System.out.println("請輸入您要乘坐的艙型"); int seat = sc.nextInt(); System.out.println("請輸入請要乘坐的月份"); int month = sc.nextInt(); switch(seat){ case 1 : if(month>=4&&month<=10){ System.out.println("旺季頭等艙打9折:"+price*0.9); }else{ System.out.println("淡季頭等艙打5折:"+price*0.5); } break; case 2: if(month>=4&&month<=10){ System.out.println("旺季經濟艙打8折:"+price*0.8); }else{ System.out.println("淡季經濟艙打4折:"+price*0.4); } default: System.out.println("請輸入有效的數值"); } } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM