Witam, miałem do napisania program "słownik polsko-angielski" takowy też napisłem prosiłbym o pomoc gdyż prowadzący stwierdził, że jest on źle napisany bo nie wolno używać static, i kazał mi go poprawić bez staticów ale nie mam pojęcia jak proszę o pomoc :)
import java.util.* ;
import java.io.* ;
public class lab09{
public static void main(String[] args) throws IOException{
menu();
}
public static void menu() throws IOException{
Scanner opcja=new Scanner(System.in);
System.out.printf("Menu:\n 1.Tlumacz\n 2.Dodaj do slownika \n 3.Wyswietl zawartosc slownika\n 4.Koniec\n");
int i=opcja.nextInt();
switch(i){
case 1: tlumacz() ; break ;
case 2: dodaj() ; break ;
case 3: wyswietl(); break;
case 4: break ;
default: System.out.printf("Nic nie wybrales!\n\n") ;
}
}
public static void tlumacz() throws IOException{
FileReader fr=new FileReader("slownik.txt") ;
Scanner linia=new Scanner(fr) ;
Scanner slowo=new Scanner(System.in) ;
LinkedList<String> pol=new LinkedList<String>() ;
LinkedList<String> ang=new LinkedList<String>() ;
String s=new String() ;
int l=0;
while(linia.hasNextLine()){
s=linia.nextLine() ;
String[] polang=s.split(" ") ;
pol.addLast(polang[0]) ;
ang.addLast(polang[1]) ;
l++ ;
}
System.out.printf("Podaj wyraz: \n") ;
s=slowo.nextLine() ;
if(pol.indexOf(s)!=-1) System.out.printf("Tlumaczenie: "+s+" - "+ang.get(pol.indexOf(s))+"\n") ;
if(ang.indexOf(s)!=-1)System.out.println("Tlumaczenie: "+s+" - "+pol.get(ang.indexOf(s))+"\n") ;
if((ang.indexOf(s)==-1)&&(pol.indexOf(s)==-1))System.out.printf("Nie ma takiego slowa w slowniku!\n") ;
System.out.printf("\n");
menu();
}
public static void dodaj() throws IOException{
FileWriter fw=new FileWriter("slownik.txt",true) ;
String s=new String() ;
Scanner slowo=new Scanner(System.in) ;
System.out.printf("Slowo i Tlumaczenie: 'pol ang' \n") ;
s=slowo.nextLine() ;
fw.write(s+"\n") ;
fw.close() ;
System.out.printf("\n") ;
menu();
}
public static void wyswietl() throws IOException{
FileReader fr=new FileReader("slownik.txt") ;
Scanner linia=new Scanner(fr) ;
while(linia.hasNextLine()){
System.out.println(linia.nextLine());
}
menu();
}
}
nikt nie ma pomysłu?