Słownik polsko-angielski - sprawdzenie

0

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?

0

ma ktoś jakiś pomysł??

0

usuń zwyczajnie static przy wszystkim za wyjątkiem main().
A main zmień tak:

public static void main(String[] args) throws IOException{
lab09 tlumacz = new lab09();
tlumacz .menu();
}
0
import java.util.* ;
import java.io.* ;

public class lab09{
public static void main(String[] args) throws IOException{
lab09 translator = new lab09();	
translator.menu();
}

public 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.Usun\n 5.Koniec\n ");
                int i=opcja.nextInt();
                switch(i){
                        case 1: tlumacz() ; break;
                        case 2: dodaj() ; break;
                        case 3: wyswietl(); break;
                        case 4: usun(); break ;
						case 5: break;
                        default: System.out.printf("Nic nie wybrales!\n\n") ;
        }
}

public 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 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 void wyswietl() throws IOException{
                FileReader fr=new FileReader("slownik.txt") ;
                Scanner linia=new Scanner(fr) ;
                while(linia.hasNextLine()){
                        System.out.println(linia.nextLine());
                                               
                }
				System.out.printf("\n");
                menu();

}

public void usun() throws IOException{
			FileReader fr = new FileReader("slownik.txt");
			Scanner slownik= new Scanner(fr);
			Scanner slowo = new Scanner(System.in);
			LinkedList<String> lista = new LinkedList<String>();
			while(slownik.hasNextLine())
			{
				lista.add(slownik.nextLine());
			}
			fr.close();

			System.out.println("Podaj slowo do usuniecia");
			String slowko;
			slowko=slowo.nextLine();
			lista.remove(slowko);

			FileWriter fw= new FileWriter("slownik.txt",false);

			for (int i=0;i<lista.size();i++)
			{
				fw.write(lista.get(i) + "\n");
			}
			fw.close();
    		System.out.printf("\n");
			menu();
}
}

dziwne .... poprawiłem ale dalej nie działa :/

0

Człowieku, to ze nie działa nie wiele mowi. napis co nie działa, jakie sa błedy itd. Nikt tutaj wrózyc raczej nie umie.

1 użytkowników online, w tym zalogowanych: 0, gości: 1