import java.net.*; import java.io.*; public class Loim5{ public static void main(String argumendid[]) throws IOException{ ServerSocket ss=new ServerSocket(3001); Object lukk=new Object(); while(true){ new Loim5abi(ss.accept(), lukk); } } } class Loim5abi extends Thread{ Socket sc; Object lukk; static String failinimi="summa.txt"; public Loim5abi(Socket usc, Object ulukk){ sc=usc; lukk=ulukk; start(); } public void run(){ try{ BufferedReader sisse=new BufferedReader( new InputStreamReader(sc.getInputStream()) ); PrintWriter valja=new PrintWriter( sc.getOutputStream(), true ); valja.println("Palun teie nimi:"); String uusnimi=sisse.readLine(); valja.println("Oota praegust hinda"); synchronized(lukk){ BufferedReader failist=new BufferedReader( new FileReader(failinimi) ); String vananimi=failist.readLine(); int vanasumma=Integer.parseInt(failist.readLine()); failist.close(); valja.println("Viimati pakkus "+vananimi+" "+vanasumma+" krooni."); valja.println("Kirjuta suurem summa voi loobumiseks pass"); String vastus=sisse.readLine(); if(!vastus.equals("pass")){ int uussumma=Integer.parseInt(vastus); if(uussumma>vanasumma){ PrintWriter faili=new PrintWriter(new FileWriter(failinimi)); faili.println(uusnimi); faili.println(uussumma); faili.close(); } } } sc.close(); }catch(Exception e){ } } }