1. 程式人生 > >2018-12-26 上機作業

2018-12-26 上機作業

一、賭場遊戲

①Sts專案展示圖

 1 package com.test;
 2 
 3 import java.util.Scanner;
 4 /**
 5  * 賭博遊戲
 6  * @author Mr.kemi
 7  *2018-12-26
 8  */
 9 public class Game {
10     public static void main(String[] args) {
11         Scanner game = new Scanner(System.in);
12         //我的錢有1000萬。
13         int money = 1000;
14 System.out.println("是否開始遊戲?Y/N"); 15 String start = game.next(); 16 //equals == 17 if(!"N".equals(start)) { 18 System.out.println("請開始下注:"); 19 int pay = game.nextInt(); 20 System.out.println("請壓大小?大/小"); 21 String Size = game.next();
22 //設定0-6的色子數 Math.random 0~1 23 int a = (int)(Math.random()*6)+1; 24 int b = (int)(Math.random()*6)+1; 25 int c = (int)(Math.random()*6)+1; 26 String result = (a+b+c)>=10?"大":"小"; 27 System.out.println("買定離手!開-"+a+","+b+","+c+","+result);
28 if(Size.equals(result)) { 29 int win = (money+pay); 30 System.out.println("中獎了"); 31 System.out.println("您的餘額為:"+win); 32 }else { 33 int lose = (money-pay); 34 System.out.println("未中獎了"); 35 System.out.println("您的餘額為:"+lose); 36 } 37 }else { 38 System.out.println("你可以走了,結束遊戲!bye"); 39 } 40 41 } 42 }

②Idea專案展示圖

 

 1 package com.test;
 2 
 3 import java.util.Scanner;
 4 /**
 5  * 賭博遊戲
 6  * @author Mr.kemi
 7  *2018-12-26
 8  */
 9 public class Game {
10     public static void main(String[] args) {
11         Scanner game = new Scanner(System.in);
12         //我的錢有1000萬。
13         int money = 1000;
14         System.out.println("是否開始遊戲?Y/N");
15         String start = game.next();
16         //equals ==
17         if(!"N".equals(start)) {
18             System.out.println("請開始下注:");
19             int pay = game.nextInt();
20             System.out.println("請壓大小?大/小");
21             String Size = game.next();
22             //設定0-6的色子數  Math.random 0~1
23             int a = (int)(Math.random()*6)+1;
24             int b = (int)(Math.random()*6)+1;
25             int c = (int)(Math.random()*6)+1;
26             String result = (a+b+c)>=10?"大":"小";
27             System.out.println("買定離手!開-"+a+","+b+","+c+","+result);
28             if(Size.equals(result)) {
29                 int win = (money+pay);
30                 System.out.println("中獎了");
31                 System.out.println("您的餘額為:"+win);
32             }else {
33                 int lose = (money-pay);
34                 System.out.println("未中獎了");
35                 System.out.println("您的餘額為:"+lose);
36             }
37         }else {
38             System.out.println("你可以走了,結束遊戲!bye");
39         }
40         
41     }
42 }

 

 

 

③eclipse專案展示圖

 1 package com.test;
 2 
 3 import java.util.Scanner;
 4 /**
 5  * 賭博遊戲
 6  * @author Mr.kemi
 7  *2018-12-26
 8  */
 9 public class Game {
10     public static void main(String[] args) {
11         Scanner game = new Scanner(System.in);
12         //我的錢有1000萬。
13         int money = 1000;
14         System.out.println("是否開始遊戲?Y/N");
15         String start = game.next();
16         //equals ==
17         if(!"N".equals(start)) {
18             System.out.println("請開始下注:");
19             int pay = game.nextInt();
20             System.out.println("請壓大小?大/小");
21             String Size = game.next();
22             //設定0-6的色子數  Math.random 0~1
23             int a = (int)(Math.random()*6)+1;
24             int b = (int)(Math.random()*6)+1;
25             int c = (int)(Math.random()*6)+1;
26             String result = (a+b+c)>=10?"大":"小";
27             System.out.println("買定離手!開-"+a+","+b+","+c+","+result);
28             if(Size.equals(result)) {
29                 int win = (money+pay);
30                 System.out.println("中獎了");
31                 System.out.println("您的餘額為:"+win);
32             }else {
33                 int lose = (money-pay);
34                 System.out.println("未中獎了");
35                 System.out.println("您的餘額為:"+lose);
36             }
37         }else {
38             System.out.println("你可以走了,結束遊戲!bye");
39         }
40         
41     }
42 }

二、switch實現135學習,246複習,週日休息

①IDEA

 1 package com.test;
 2 
 3 import java.util.Scanner;
 4 
 5 /**
 6  * 這是一週的Switch選擇結構
 7  * @author Mr.kemi
 8  *2018-12-26
 9  */
10 public class Week {
11     public static void main(String[] args) {
12         Scanner week = new Scanner(System.in);
13         System.out.println("親愛的,今天周幾呀");
14         int day = week.nextInt();
15         System.out.println("今天是周"+day);
16         switch (day) {
17             //週一週三週五要學習。
18         case 1:
19         case 3:
20         case 5:
21             System.out.println("小可愛你今天要學習哦");
22             break;
23             //週二週四週六要複習。
24         case 2:
25         case 4:
26         case 6:
27             System.out.println("小可愛你今天要複習哦");
28             break;    
29         default:
30             //週日休息
31             System.out.println("你今天休息啊,我們出去玩吧");
32             break;
33         }
34     }
35 }

 

 

②STS

 1 package com.test;
 2 
 3 import java.util.Scanner;
 4 
 5 /**
 6  * 這是一週的Switch選擇結構
 7  * @author Mr.kemi
 8  *2018-12-26
 9  */
10 public class Week {
11     public static void main(String[] args) {
12         Scanner week = new Scanner(System.in);
13         System.out.println("親愛的,今天周幾呀");
14         int day = week.nextInt();
15         System.out.println("今天是周"+day);
16         switch (day) {
17             //週一週三週五要學習。
18         case 1:
19         case 3:
20         case 5:
21             System.out.println("小可愛你今天要學習哦");
22             break;
23             //週二週四週六要複習。
24         case 2:
25         case 4:
26         case 6:
27             System.out.println("小可愛你今天要複習哦");
28             break;    
29         default:
30             //週日休息
31             System.out.println("你今天休息啊,我們出去玩吧");
32             break;
33         }
34     }
35 }

 

③eclipse

 1 package com.test;
 2 
 3 import java.util.Scanner;
 4 
 5 /**
 6  * 這是一週的Switch選擇結構
 7  * @author Mr.kemi
 8  *2018-12-26
 9  */
10 public class Week {
11     public static void main(String[] args) {
12         Scanner week = new Scanner(System.in);
13         System.out.println("親愛的,今天周幾呀");
14         int day = week.nextInt();
15         System.out.println("今天是周"+day);
16         switch (day) {
17             //週一週三週五要學習。
18         case 1:
19         case 3:
20         case 5:
21             System.out.println("小可愛你今天要學習哦");
22             break;
23             //週二週四週六要複習。
24         case 2:
25         case 4:
26         case 6:
27             System.out.println("小可愛你今天要複習哦");
28             break;    
29         default:
30             //週日休息
31             System.out.println("你今天休息啊,我們出去玩吧");
32             break;
33         }
34     }
35 }

 

 三、海南旅遊,旺季淡季的價格計算

 1 package com.test;
 2 import java.util.Scanner;
 3 /**
 4  * 海南機票價格輸出
 5  * @author Mr.kemi
 6  *2018-12-26
 7  *Ticket·機票
 8  */
 9 public class Ticket {
10     public static void main(String[] args) {
11         Scanner ticket = new Scanner(System.in);
12         System.out.println("尊敬的海南乘客,請輸入您出行的月份:1~12");
13         //出行的月份
14         int month = ticket.nextInt();
15         //機票原價
16         int price = 5000;
17         System.out.println("請問您選擇頭等艙還是經濟艙?頭等艙輸入1,經濟艙輸入2");
18         //seat·座位
19         int seat = ticket.nextInt();
20         switch (month) {
21             case 4:
22             case 5:
23             case 6:
24             case 7:
25             case 8:
26             case 9:
27             case 10:
28             //使用條件運算子算出旺季的價格  seat_seat賦值給它輸出
29             double seat_seat = seat==1?(price*0.9):(price*0.6);
30             System.out.println("您的價格是:"+seat_seat);
31             break;
32         default:
33             //使用條件運算子算出淡季的價格  seatSeat賦值給它輸出
34             double seatSeat = seat==1?(price*0.5):(price*0.5);
35             System.out.println("您的價格是:"+seatSeat);
36             
37         }
38     }
39 }

 

 

 

 

連結:https://pan.baidu.com/s/1VvD961n6snvHY-xtnB5ipQ
提取碼:kwee
複製這段內容後開啟百度網盤手機App,操作更方便哦