搜索
熱搜: 活動 交友 discuz
查看: 1554|回復: 0
打印 上一主題 下一主題

[教學] IVE Programming Assignment Dec 20, 2005

[複製鏈接]
跳轉到指定樓層
1#
發表於 2007-7-27 21:11:28 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
// 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 + " 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 = Integer.parseInt(input_num_st);
      
      for (int ii = 0; ii < input_num_ar.length; ii++) {
        if (input_num_ar == input_num_ar[ii] && i != ii) {
          JOptionPane.showMessageDialog(null, error_msg_sm);
          i--;
          break;
        } else if (input_num_ar < 1 || input_num_ar > 49) {
          JOptionPane.showMessageDialog(null, error_msg_bg);
          i--;
          break;
        }
      }
    }
   
    for (int i = 0; i < lot_num_ar.length; i++) {
      lot_num_ar = (int)(Math.random() * 100);
      
      for (int ii = 0; ii < lot_num_ar.length; ii++) {
        if (lot_num_ar == lot_num_ar[ii] && i != ii) {
          i--;
          break;
        } else if (lot_num_ar < 1 || lot_num_ar > 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 == input_num_ar[ii] && i == 6) {
          flag += 5;
          break;
        } else if (lot_num_ar == 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;
        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 < 10) {
        space = " ";
      } else {
        space = "";
      }
      if (i != 0) {
        System.out.print(", ");
      }
      System.out.print(space + lot_num_ar);
    }
   
    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 < 10) {
        space = " ";
      } else {
        space = "";
      }
      if (i != 0) {
        System.out.print(", ");
      }
      System.out.print(space + input_num_ar);
    }
   
    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 > num_result[i + 1]) {
            exchange = num_result;
            num_result = num_result[i + 1];
            num_result[i + 1] = exchange;
          } else {
            continue;
          }
        }
      }
    }    // End Bubble Sort Method
  }
}
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

本論壇為非營利之網路平台,所有文章內容均為網友自行發表,不代表論壇立場!若涉及侵權、違法等情事,請告知版主處理。


Page Rank Check

廣告刊登  |   交換連結  |   贊助我們  |   服務條款  |   免責聲明  |   客服中心  |   中央分站

手機版|中央論壇

GMT+8, 2024-5-15 21:01 , Processed in 0.057553 second(s), 17 queries .

Powered by Discuz!

© 2005-2015 Copyrights. Set by YIDAS

快速回復 返回頂部 返回列表