타자연습 1 - 2 이내에 걸구룹 지워야 한다 > 오픈소스 | IOTsw_u2 U2 Project
오픈소스

JAVA 타자연습 1 - 2 이내에 걸구룹 지워야 한다

본문

import java.util.*;
class import java.util.*;
class TypingGameEx1 
{
	Vector words = new Vector() ;
	String[] data = 
	{
		"태연","유리","윤아","효연","수영","서현","티파니","써니","제시카"};
		int interval = 2 * 1000;
		// 2초
		WordGenerator wg = new WordGenerator() ;
		public static void main(String args[]) 
		{
			TypingGameEx1 game = new TypingGameEx1() ;
			game.wg.start() ;
			Vector words = game.words;
			while(true) 
			{
				System.out.println(words) ;
				String prompt = ">>";
				System.out.print(prompt) ;
				// 화면으로부터 라인단위로 입력받는다. 
				Scanner s = new Scanner(System.in) ;
				String input = s.nextLine() .trim() ;
				/*
                     다음의 코드를 완성하세요.
 
                    1. 사용자가 입력한 값을 words에서 찾아 제거한다.
                 */
				if(words.contains(input)) 
				{
					words.remove(input) ;
				}

			}

		}

		// main
		public void delay(int millis) 
		{
			try 
			{
				Thread.sleep(millis) ;
			}
			catch(Exception e) 
			{
				
			}
		}

		class WordGenerator extends Thread 
		{
			public void run() 
			{
				while(true) 
				{
					int max = data.length;
					//System.out.println(max);
					int val = (int) (Math.random() * max) ;
					//System.out.println(val);
					words.add(data[val]) ;
					delay(1000) ;
					//System.out.println();
					//System.out.println(words); 
					//String prompt = ">>"; 
					//System.out.print(prompt); 
				}
			/*
			WordGenerator는 일정시간(interval) 간격으로 data배열의 한 요소를 골라서
			words(Vector인스턴스)에 저장하는 일을 수행한다.
			다음의 코드를 완성하세요.
			1. 문자열 배열 data의 임의의 요소를 골라서 words(Vector인스턴스)에 저장한다.
			2. 인스턴스 변수 interval의 값만큼 시간간격을 둔다.
			3. 반복문을 이용해서 1,2의 작업이 반복적으로 이루어지게 한다.
			*/
			}
			// end of run() 
		}

	// class WordGenerator 
	}

	// TypingGameEx1 { 
      Vector words = new Vector(); 
      String[] data = {"태연","유리","윤아","효연","수영","서현","티파니","써니","제시카"};             
      int interval = 2 * 1000; // 2초
      WordGenerator wg = new WordGenerator();
      public static void main(String args[]) { 
            TypingGameEx1 game = new TypingGameEx1();
            game.wg.start();
            Vector words = game.words;
            while(true) { 
                  System.out.println(words);
                  String prompt = ">>"; 
                  System.out.print(prompt);
                  // 화면으로부터 라인단위로 입력받는다. 
                  Scanner s = new Scanner(System.in); 
                  String input = s.nextLine().trim();
                  /*
                     다음의 코드를 완성하세요.
 
                    1. 사용자가 입력한 값을 words에서 찾아 제거한다.
                 */
                  if(words.contains(input))
                  {
                   words.remove(input);
                  }
                  
            } 
      } // main
      public void delay(int millis) { 
            try { 
                  Thread.sleep(millis); 
            } catch(Exception e) {} 
      }
 
      class WordGenerator extends Thread { 
            public void run() {
             
             while(true)
             {
              int max = data.length;
              //System.out.println(max);
              int val = (int)(Math.random() * max);
              //System.out.println(val);
              words.add(data[val]);
              delay(1000);
              //System.out.println();
                    //System.out.println(words); 
                    //String prompt = ">>"; 
                    //System.out.print(prompt); 
             }
				/*
				WordGenerator는 일정시간(interval) 간격으로 data배열의 한 요소를 골라서
				words(Vector인스턴스)에 저장하는 일을 수행한다.

				다음의 코드를 완성하세요.
				1. 문자열 배열 data의 임의의 요소를 골라서 words(Vector인스턴스)에 저장한다.
				2. 인스턴스 변수 interval의 값만큼 시간간격을 둔다.
				3. 반복문을 이용해서 1,2의 작업이 반복적으로 이루어지게 한다.
				*/
            } // end of run() 
      } // class WordGenerator 
} // TypingGameEx1

 

댓글목록

오픈소스 목록

Total 16건 1 페이지
게시물 검색

IOTsw_u2 정보

회사 . U2
주소 . 어느별 하늘 아래에 있것지요
사업자 등록번호 . 백수임 대표 . 김씨 전화 . 02-123-4567 팩스 . 팩스없음
통신판매업신고번호 . 낼할께 개인정보관리책임자 . 김씨가 알아서 함 부가통신사업신고번호 신고안함
Copyright © 2001-2013 U2. All Rights Reserved.
닫기