2018年10月31日 星期三

[Java]_ch9.3_威力彩繼承大樂透





[ 物件導向實作 ]
利用繼承觀念extends Loto.java
並新增威力彩方法與改寫Loto方法



import java.io.*;

public class Weili extends Loto

{

int n6;

public Weili(int n) {

super(n);

}

public int UserInput() throws IOException{

System.out.print("[樂透遊戲]1.自選、2.隨機、3威力彩: ");

String s=buf.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:

weiliLoto();

sort(A);

break;

default:

System.out.println("無此選項...");

}

}

public void weiliLoto()throws IOException

{

System.out.println("[威力彩自選號碼::第1區38選6,第2區8選1,共七個號碼]");

for (int i=0;i<6;i++)

{

System.out.print("請輸入第一區,第"+(i+1)+"個號碼:");

A[i]=Integer.parseInt(buf.readLine());

for(int j=0;j<i;j++)

{

if(A[i]==A[j] )

{

System.out.println("重複了喔,請重新輸入第"+(i+1)+"個數:");

i--;

}else if(A[i]>38 || A[i]<1){

System.out.println("數值超出1~38範圍!,請重新輸入第"+(i+1)+"個數:");

i--;

}

}

}

System.out.print("請輸入第二區的號碼:");

n6=Integer.parseInt(buf.readLine());

System.out.println("你自選的第一區號碼為:"+A[0]+" "+A[1]+" "+A[2]+" "+A[3]+" "+A[4]+" "+A[5]+" 第二區號碼: "+n6);

}

public void sort(int A[])

{

System.out.print("威力彩: 第1區: "+A[0]+" "+A[1]+" "+A[2]+" "+A[3]+" "+A[4]+" "+A[5]+",第2區: "+n6);

System.out.println();

System.out.print("sort array: ");

int tmp;

for(int k=A.length;k>1;k--) //從小到大的排序

{

for(int j=0;j<A.length-1;j++)

{

if(A[j]>A[j+1])

{

tmp=A[j+1];

A[j+1]=A[j];

A[j]=tmp;

}

}

}

for(int j=0;j<A.length;j=j+1)

{

System.out.print(A[j]+" ");

}

System.out.print(",第2區: "+n6);

System.out.println();

}

}




沒有留言:

張貼留言

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