티스토리 뷰

Java - 영어단어 프로그램!

 

 

txt 파일에

 

영어단어 뜻 영어단어 뜻 순서대로 입력한뒤 사용하시면 됩니다.

 

 

 

영어단어와 뜻 구별은 스페이스바로 구별됩니다.

 

 

cmd 창으로 컴파일해서 사용하면 좋습니다.

 

 

 

 

public class test_English {
 public static void main(String[] args){
  int count = 0; //단어의 개수
  int count2 = 0; //단어 저장용 카운트
  int score = 0; //맞은개수
  int total = 0; // 점수
  String text[]; //영어 단어
  String korean[]; //영어단어의 뜻
  String input[]; //입력받는 정답

  text = new String[100]; //단어개수만큼 배열을 생성한다
  korean = new String[100]; //뜻의 개수만큼 배열을 생성한다.
  input = new String[100];
  Scanner scanner = new Scanner(System.in); //입력받는 인스턴스 생성
  
  
  try{
   FileInputStream ip = new FileInputStream("quest.txt"); //txt파일 오픈 다른경로가 지정되지 않을시 소스파일이 있는곳에 생성
   
   Scanner s = new Scanner(ip); //txt 파일 읽어오는 스캐너 생성
   
   
   
   while(true){
    if(s.hasNext()){    // hasNext()를 통해 요소가 남아있는지 확인함 남아있으면 true가 반환됨
     text[count2] = s.next();
     korean[count2] = s.next();
     count2+=1;
     count+=1;
     //요소를 읽어와서 저장 //next()는 한단어를 읽어오고, nextLine()은 한 문장을 읽어온다.
    }else{
     break;
    }
   }
    
   
   }catch(Exception e){
    e.printStackTrace();
  }
  
            for(int j=0;j < count;j++){ //문제 출제!!
            System.out.print(j+1+": ");
   System.out.print(korean[j]+" ");
   input[j] = scanner.next();
   System.out.println();
  }
           
            for(int j=0;j <count;j++){ // 맞은개수를 확인한다!
             if(text[j].equalsIgnoreCase(input[j])){ //equals에 대해서는 쓸모없는 프로그램 1편에서 확인
              score+=1;
             }
            }
            total = 100/count*score;
            System.out.println("당신의 점수: "+total);
            if(total < 20) {
             System.out.println("열심히 하세요!");
            }else if(total > 20 && total < 50){
             System.out.println("힘내라 힘!");
            }else if(total > 50 && total < 100){
             System.out.println("조금만 더!");
            }else if(total == 100){
             System.out.println("스고이 데스네");
            }
 }
}

 

 

 


'잡담 > 포트폴리오' 카테고리의 다른 글

대덕 소프트웨어 마이스터고 안드로이드 앱  (0) 2015.12.04
ProLan FileGate  (0) 2015.06.09
java - 채팅프로그램  (2) 2015.05.31
java - 영어단어 암기 프로그램  (2) 2015.04.01
Java - 쓸모없는 프로그램(1)  (0) 2015.03.21
댓글
최근에 올라온 글
최근에 달린 댓글
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
글 보관함