- // Assignment of 20 Dec 2005 About Mark Six Edit By Stephen Chung Kam Chin
- import javax.swing.*;
- public class Assignment_20Dec2005_Mark_Six {
-
- static String input_num_st; // Save the input number as String Type
- static String prize; // The winning message will be show
- static String space; // Add the suitable space on the number
- static int input_num_ar[]; // Define the input number array
- static int lot_num_ar[]; // Define the lot number array
- static int lucky_num_ar[]; // Define the lucky number array
- static String num_order_ar[] = {"First", "Second", "Third", "Fourth", "Five", "Sixth"}; // Define and New the stage number
- static String prize_ar[] = {"6th Prize", "6th Prize", "5th Prize", "4th Prize", "3th Prize", "2th Prize", "1th Prize", "SORRY! You are fail to got a Prize!"};
- static String congrat[] = {"\n\nCongratualation... You got a ", "!!!"};
- static String show_heading[] = {"The generated numbers are:", "Your inputs are:"};
- static int flag; // Calculation which prize to be winning
- static int exchange; // Temporary Variable of exchange of value of Bubble Sort Method
- static String dialog_title = "The Six Mark System";
- static String error_msg_sm = "Please Don't Input The Same Number";
- static String error_msg_bg = "Please Enter The Number Between 1 - 49";
- static String error_msg_int = "Please Enter The Correct Integer Number";
- static boolean error_char;
- static int input_num_len;
- static final String HELP = "This is a six mark system.\nIf you have any problem, Please Contact Stephen(Designer)";
- public static void main(String[] args) {
-
- input_num_ar = new int[6];
- lot_num_ar = new int[7];
- lucky_num_ar = new int[1];
-
- for (int i = 0; i < input_num_ar.length; i++) {
- input_num_st = JOptionPane.showInputDialog(null, "Input The " + num_order_ar[i] + " Number", dialog_title,
- JOptionPane.QUESTION_MESSAGE);
-
- if (input_num_st == null) {
- i--;
- Object[] options = { "OK", "CANCEL", "HELP" };
- int confirm = JOptionPane.showOptionDialog(null, "Click OK to Exit.\nClick CANCEL To Continue", "CONFIRM MESSAGE",
- JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
- null, options, options[0]);
-
- if (confirm == 0) {
- return;
- } else if (confirm == 1) {
- continue;
- } else if (confirm == 2) {
- JOptionPane.showMessageDialog(null, HELP);
- continue;
- }
- }
-
- input_num_len = 0;
- input_num_len = input_num_st.length();
- if (input_num_len == 0) {
- JOptionPane.showMessageDialog(null, error_msg_int);
- i--;
- continue;
- }
-
- error_char = false;
- for (int i_2 = 0; i_2 < input_num_st.length(); i_2++) {
- char c = input_num_st.charAt(i_2);
- int ii = (int)c;
- if (ii < 48 || ii > 57) {
- JOptionPane.showMessageDialog(null, error_msg_int);
- error_char = true;
- break;
- }
- }
-
- if (error_char == true) {
- i--;
- continue;
- }
-
- input_num_ar[i] = Integer.parseInt(input_num_st);
-
- for (int ii = 0; ii < input_num_ar.length; ii++) {
- if (input_num_ar[i] == input_num_ar[ii] && i != ii) {
- JOptionPane.showMessageDialog(null, error_msg_sm);
- i--;
- break;
- } else if (input_num_ar[i] < 1 || input_num_ar[i] > 49) {
- JOptionPane.showMessageDialog(null, error_msg_bg);
- i--;
- break;
- }
- }
- }
-
- for (int i = 0; i < lot_num_ar.length; i++) {
- lot_num_ar[i] = (int)(Math.random() * 100);
-
- for (int ii = 0; ii < lot_num_ar.length; ii++) {
- if (lot_num_ar[i] == lot_num_ar[ii] && i != ii) {
- i--;
- break;
- } else if (lot_num_ar[i] < 1 || lot_num_ar[i] > 49) {
- i--;
- break;
- }
- }
- }
-
- flag = 0;
- for (int i = 0; i < lot_num_ar.length; i++) {
- for (int ii = 0; ii < input_num_ar.length; ii++) {
- if (lot_num_ar[i] == input_num_ar[ii] && i == 6) {
- flag += 5;
- break;
- } else if (lot_num_ar[i] == input_num_ar[ii]) {
- flag += 10;
- break;
- }
- }
- }
-
- lucky_num_ar[0] = lot_num_ar[6]; // Insert the lucky number into lucky number array
-
- int ii = 30; // Start matching the prize, 30 = 3 numbers hit
- for (int i = 0; i < 8; i++) {
- if (ii == flag || ii > 60) {
- prize = prize_ar[i];
- break;
- }
- ii += 5;
- } // End matching the prize
- bubble_sort(lot_num_ar); // Put lot number into bubble sort
- bubble_sort(input_num_ar); // Put input number into bubble sort
-
- System.out.println(show_heading[0]);
- for(int i = 0; i < lot_num_ar.length - 1; i++) {
- if (lot_num_ar[i] < 10) {
- space = " ";
- } else {
- space = "";
- }
- if (i != 0) {
- System.out.print(", ");
- }
- System.out.print(space + lot_num_ar[i]);
- }
-
- System.out.print(" + " + lucky_num_ar[0] + "\n\n");
- System.out.println(show_heading[1]);
-
- for(int i = 0; i < input_num_ar.length; i++) {
- if (input_num_ar[i] < 10) {
- space = " ";
- } else {
- space = "";
- }
- if (i != 0) {
- System.out.print(", ");
- }
- System.out.print(space + input_num_ar[i]);
- }
-
- if (flag >= 30) {
- System.out.println(congrat[0] + prize + congrat[1]);
- } else {
- System.out.println("\n\n" + prize);
- }
- }
-
- public static void bubble_sort(int num_result[]) { // Start Bubble Sort Method
- for (int pass = 1; pass < num_result.length; pass++) {
- for (int i = 0; i < num_result.length - 1; i++) {
- if (i > 4) {
- continue;
- } else {
- if (num_result[i] > num_result[i + 1]) {
- exchange = num_result[i];
- num_result[i] = num_result[i + 1];
- num_result[i + 1] = exchange;
- } else {
- continue;
- }
- }
- }
- } // End Bubble Sort Method
- }
- }
複製代碼
[ Last edited by 野貓 on 2005-11-17 at 09:24 PM ]... |