티스토리 뷰

개발/산출물(java)

Lotto 프로그램(1일차)

개발자와코더사이가 PM일까? 2012. 2. 19. 06:26
반응형

//목표 : 내가 가지고 있는 번호가 한번이라도 1등에 당첨이 되었는지 확인하는 프로그램.
//성과 : 미완성 : 객체지향을 무슨 절차지향처럼 만들었음
//버그가 너무 많음..2일차로 넘김.
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

import java.util.Scanner;


public class start {

 public static void main(String[] args) {
  start();//시작하는점
 }

 private static void start() {
  int intSelectNumber = 0; //선택번호
  
  System.out.println("===================");  
  System.out.println("로또 프로그램을 선택합니다.");
  System.out.println("1.내번호로 당첨번호 확인하기");
  System.out.println("2.차기 당첨번호 추출하기");
  System.out.println("===================");
  Scanner in = new Scanner(System.in) ;

  intSelectNumber = in.nextInt() ;   
  in.nextLine();
  
  if (intSelectNumber==1)
  {
   selectMyNumber();
  }
  else if(intSelectNumber==2)
  {
   MakeNextNumber();
  }
  
 }

 private static void MakeNextNumber() {
  System.out.println("2번을 선택했습니다."); 
  System.out.println("아직구현이 안됐습니다.");  
 }

 
 private static void selectMyNumber() {

  ArrayList<String> lists = new ArrayList<String>();
  String StringInputNumber ="";
  int intCheckNumber=0;
  
  StringInputNumber = inputNumber();//문자열을 입력받는다.
  intCheckNumber = CheckNumber(StringInputNumber);//문자열이 제대로 됐는지 확인한다.

  //1번째배열은 회차
  //2~7번째배열은 번호
  //8번째 보너스
  
  if(intCheckNumber != 0)
  {
   System.out.println("아이쿠 숫자는 제대로 들어왔어"+StringInputNumber);    
   ReadLottoFile(); 
  }
  else
  {
   System.out.println(StringInputNumber+ " : 입력 숫자형식이 잘못되었습니다. 다시 프로그램을 시작하세요");
   return;
  }
 
 }
 
 
 @SuppressWarnings("null")
 private static void ReadLottoFile() {
  
  FileInputStream fis = null;
  byte input[] = null;

  File f = new File("C:/mata.txt");
  if(!f.exists())
  {
   System.out.println("파일없음");
  }
  else
  {
   try
   {
     fis = new FileInputStream("C:/mata.txt");
  
     int size = fis.available();//읽어 들일수 있는 추정바이트수
     //System.out.println(size);//파일의 크기
     input = new byte[size];
  
        int lne = 0;
        String strMataData = null;
        String []  stringArrayOne = null;
        String []  stringArrayTwo = null;
        int [][] intArrayThree = null;
       
    while((lne = fis.read(input))>-1)
    {
     strMataData = new String(input);
     stringArrayOne = strMataData.split("\\*");
     
     
     for(int i=0; i<stringArrayOne.length; i++)
     {
      for(int j = 0; j<8;j++)
      {
       stringArrayTwo = stringArrayOne[i].split("\\,");
       System.out.println(stringArrayTwo[j].toString()); 
       /*String s = stringArrayTwo[j].trim();
       
       if(stringArrayTwo[j].trim() != null || stringArrayTwo[j].trim() != "")
       {
        System.out.println(s); 
        //int kk = (Integer.parseInt(stringArrayTwo[j].trim()));
       }
       //int kk = (Integer.parseInt(stringArrayTwo[j].trim()));
       //intArrayThree[i][j] = kk;
*/      }
      
     }
     
     System.out.println("========기준데이터===============");     
     System.out.println("회차:1번,2번,3번,4번,5번,6번,보너스번호");
     System.out.println(strMataData);
    }
    
    /*System.out.println("****회차: "+stringArrayThree[0][0]);
    System.out.println("****1번째: "+stringArrayThree[0][1]);
    System.out.println("****2번째: "+stringArrayThree[0][2]);
    System.out.println("****3번째: "+stringArrayThree[0][3]);
    System.out.println("****4번째: "+stringArrayThree[0][4]);
    System.out.println("****5번째: "+stringArrayThree[0][5]);
    System.out.println("****6번째: "+stringArrayThree[0][6]);
    System.out.println("****보너스: "+stringArrayThree[0][7]);
    */
    /*for(int i=0; i<stringArrayOne.length;i++)
    {
     for(int j = 0; j<8;j++)
     {
      stringArrayTwo[i];
     }
     //System.out.println(s[i].toString());      
    }*/
   }
   catch(Exception ex)
   {
    System.out.println(ex.toString()+ " : 111병신 무엇인가 에러를 만들었네");
   }
  }
  
 }

 //문자열이 제대로 됐는지 확인한다.
 private static int CheckNumber(String stringInputNumber) {
  
  int intReturn = 0;
  int intCheckNumber = 0;
  int intDuplicate =0;
  String stringInputNumber1 = "";
  try
  {
   stringInputNumber1 = stringInputNumber;
   
   //제대로 된 수를 넣는지 확인을 해야 한다.
   if(stringInputNumber1=="" || stringInputNumber1==null || stringInputNumber1== " " || stringInputNumber1=="\n")
   {
    System.out.println("빈문자열을 입력하셨습니다. 다시 입력하세요");
    intReturn = 0;
   }
   else
   {
    String[] stringArrayInputNumber = stringInputNumber1.split(",");

    //1~45 또는 , 만 받아야 한다.
    for(int i=0; i<stringArrayInputNumber.length;i++)
    {
     String s = stringArrayInputNumber[i].toString();

     int intParseNumber = Integer.parseInt(s);

     if (intParseNumber < 0  ||  intParseNumber > 46)
     {
      intCheckNumber ++;
     }
     
     int intCheckNum = 0;
     //중복값을 넣으면 안된다.
     for(int d = 0; d<stringArrayInputNumber.length;d++)
     {
      
      String strDuplicate = stringArrayInputNumber[d].toString();
      
      if(intParseNumber == Integer.parseInt(strDuplicate))
      {       
       intCheckNum++;
      } 
       
      if(intCheckNum-1 > 1)
      {
       intCheckNumber ++;
      }
     }
     
    }
           
    if(intCheckNumber>0)
    {
     intReturn=0;
    }else
    {
     intReturn=1;     
    }
    
   }

  }
  catch(Exception ex)
  {
   System.out.println("CheckNumber 함수에서 문제가 생겼습니다. 개발장에게 연락을 주세요");   
   System.out.println(ex.toString());   
   intReturn = 0;
  }
  
  return intReturn;
  
 }

 //문자열을 입력받는다.
 private static String inputNumber() {
  String StringInputNumber ="";
  InputStreamReader insr = new InputStreamReader(System.in);
  BufferedReader inbr = new BufferedReader(insr);

  System.out.println("1번을 선택하셨습니다.");
  System.out.println("번호를 6개을 아래와 같이 입력해주세요");
  System.out.println("예시 ========>1,2,3,4,5,6");

  try {
   //if (inbr.readLine() != null)
   //{
    StringInputNumber = inbr.readLine();
   //}
   
  } catch (Exception ex) {
   System.out.println("inputNumber 함수에서 문제가 생겼습니다. 개발장에게 연락을 주세요");   
   System.out.println(ex.toString());
  }
  
  return StringInputNumber;
 }

 
}

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함