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,操作更方便哦