2019年8月21日 星期三

[Java程式]_Ch9.3_物件導向範例實作







1 則留言:

  1. import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;

    public class Game extends Loto{

    public Game(int n) {
    super(n);
    }
    public int userInput() throws IOException{
    System.out.print("[遊戲大集合]\n1.自選、2.隨機、3.終極密碼、4.猜數字、5.陳水扁: ");
    String s=br.readLine();
    int usr=Integer.parseInt(s);
    return usr;
    }
    public void platForm(int usr) throws IOException{
    switch(usr){
    case 1:
    selfLoto();
    break;
    case 2:
    randomLoto();
    break;
    case 3:
    PWD();
    break;
    case 4:
    GuessPWD pwd=new GuessPWD();
    pwd.guess();
    break;
    case 5:
    陳水扁 阿扁=new 陳水扁();
    阿扁.信眾(1000);
    break;
    default:
    System.out.println("很抱歉無"+usr+"這個選項...");
    }
    }
    public void PWD() throws IOException{
    int pc=(int)(Math.random()*100+1),usr,L=1,R=100;
    System.out.println("pc:"+pc);
    do{
    System.out.print("請輸入"+L+"~"+R+": ");
    String s1=br.readLine();
    usr=Integer.parseInt(s1);
    if(usr==pc)
    System.out.println("恭喜答對!");
    else{
    System.out.println("抱歉答錯!");
    if(usr>pc)
    R=usr;
    else
    L=usr;
    }
    }while(usr!=pc);
    System.out.println("遊戲結束...");
    }
    }

    回覆刪除

Ether.fi Cash Card 一張所有人必備的加密貨幣信用卡   [Ether.fi Cash Card] : https://www.ether.fi/app/cash/sign-up?ref_code=d27f8523 ------國際交易所------ [Bitg...