안녕하세요 저는 텍스트 문서의 단어 + 정의를 가져 와서 그들을 스크램블 한 다음에 그들을 퀴즈하는 프로그램을 만들고 있습니다. 단어는 (단어 : 정의)로 구성됩니다.
나는 프로젝트를위한 코드를 끝냈다. 그러나 내가 컴파일 한 후에 어떤 이유로 콘솔은 공란으로 남는다.프로젝트가 컴파일되지만 컴파일러의 정보를 표시하지 않습니다.
public class VocabularyWord {
private String word, definition;
public VocabularyWord(String w, String d){
word=w;
definition=d;
}
public String getDefinition(){
return definition;
}
public String getWord(){
return word;
}
public String toString(){
return word+" "+definition;
}
}
2 급 : - - :
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class VocabularyTest {
private ArrayList<VocabularyWord>words;
private int c;
public VocabularyTest() throws FileNotFoundException{
words=new ArrayList<VocabularyWord>();
ArrayList<String> str=new ArrayList<String>();
File inputFile = new File("Vocabulary.txt");
Scanner input = new Scanner(inputFile);
while(input.hasNextLine()){
str.add(input.nextLine());
processStrings(str);
for(int i = 0; i<100; i++)
swapWords();
}
}
private void processStrings(ArrayList<String>lines){
int pos=0;
for(int i=lines.size()-1; i>=0; i--){
pos=lines.get(i).indexOf(":");
String s=lines.get(i).substring(0, pos);
String ss=lines.get(i).substring(pos+1, lines.get(i).length());
VocabularyWord p=new VocabularyWord(s,ss);
words.add(p);
c++;
}
}
private void swapWords(){
int x=(int) (Math.random()*words.size());
int xx=(int)(Math.random()*words.size());
while(x==xx)
xx=(int)(Math.random()*words.size());
Collections.swap(words, xx, x);
}
public void quiz(){
System.out.println("hi");
int n=0;
Scanner kb=new Scanner(System.in);
for(int i=words.size()-1; i>=0; i--){
System.out.println(words.get(i).getDefinition());
if(kb.nextLine().equals(words.get(i).getWord())){
System.out.println("Nice Job!");
n++;
}
else
System.out.println(words.get(i).getWord());
}
System.out.println("You got "+n+" correct!");
}
}
등급 3 : -
1 등급 :
코드는 내가 아래에 표시됩니다 세 개의 클래스로 구성
import java.io.FileNotFoundException;
public class VocabTestTester {
public static void main(String[] args)throws FileNotFoundException{
VocabularyTest test= new VocabularyTest();
test.quiz();
}
}
는 아마 프로그램을 디버깅 할 때입니다. 당신은 진술한다,''내가 컴파일 한 후에 콘솔은 공백으로 남는다 ... "'- 실제로 ** ** 컴파일 후에 프로그램을 실행합니까? –
죄송합니다. 나는 컴파일하고 실행하는 것을 의미합니다. – nebularis
** ** ** 당신은 그것을 어떻게 운영하고 있습니까? –