Witam! Niektórzy z was kojarzą już ten program xD przerobiłem go trochę kompiluje się uruchamia, ale jest jeden okropny problem: Klasa Pracownik wywołuje metode zapisu do pliku tekstowego z klasy File. Niestety po wpisaniu wartosci i przerwaniu petli program sie dalej nie wykonuuje, mimo, że w klasie pracownik wywoluje też dwie inne metody. Co mam zrobić, żeby to działało??
Program składa się z 3 klas, więc proszę o cierpliwość w szukaniu błędu :) Naprawdę nie wiem jak mam to zrobić :((
1.
package ćw6;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;
public class File
{
static Set<String> SetNames = new HashSet<String>();
static Set<String> SetSurnames = new HashSet<String>();
static LinkedList<String> ListNames = new LinkedList<String>();
static LinkedList<String> ListSurnames = new LinkedList<String>();
public static void record() throws IOException
{
Scanner scanner = new Scanner(System.in);
PrintStream namesWriter = new PrintStream("Names.txt");
PrintStream surnamesWriter = new PrintStream("Surnames.txt");
System.out.println("Podawaj imiona i nazwiska. Wyraz \"stop\" kończy wpisywanie\n");
System.out.print("Podaj imię: ");
String name = scanner.nextLine();
System.out.print("Podaj nazwisko: ");
String surname = scanner.nextLine();
while (((name.equalsIgnoreCase("stop")) || (surname.equalsIgnoreCase("stop"))) == false)
{
namesWriter.println(name);
surnamesWriter.println(surname);
System.out.print("Podaj imię: ");
name = scanner.nextLine();
System.out.print("Podaj nazwisko: ");
surname = scanner.nextLine();
}
System.out.println("\nWpisywanie zakończone!");
namesWriter.close();
surnamesWriter.close();
scanner.close();
}
public static LinkedList<String> readingNames() throws FileNotFoundException, IOException
{
try
{
FileReader readNames = new FileReader("Names.txt");
BufferedReader bufferedReaderNames = new BufferedReader(readNames);
String line = bufferedReaderNames.readLine();
while (line != null)
{
SetNames.add(line);
line = bufferedReaderNames.readLine();
}
ListNames.addAll(SetNames);
bufferedReaderNames.close();
readNames.close();
} catch (FileNotFoundException e)
{
System.err.println("Nie można odnalezć pliku o nazwie \"Names.txt\"");
} catch (IOException e)
{
System.err.println("Nieznany błąd wejścia typu Input-Output");
}
return ListNames;
}
public static LinkedList<String> readingSurnames()
{
try
{
FileReader readSurnames = new FileReader("Surnames.txt");
BufferedReader bufferedReadSurnames = new BufferedReader(readSurnames);
String line = bufferedReadSurnames.readLine();
while (line != null)
{
SetSurnames.add(line);
line = bufferedReadSurnames.readLine();
}
ListSurnames.addAll(SetSurnames);
bufferedReadSurnames.close();
readSurnames.close();
} catch (FileNotFoundException e)
{
System.err.println("Nie można znalezć pliku o nazwie \"Surnames.txt\"");
} catch (IOException e)
{
System.err.println("Nieznany błąd wejścia typu Input-Output");
}
return ListSurnames;
}
}
2.
package ćw6;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Random;
public class Pracownik extends File
{
String name;
String surname;
int age;
static LinkedList<String> lista1 = new LinkedList<String>();
static LinkedList<String> lista2 = new LinkedList<String>();
public Pracownik() {}
public void setName(String name)
{
name = lista1.removeLast();
this.name = name;
}
public String getName()
{
return name;
}
public void setSurname(String surname)
{
surname = lista2.removeLast();
this.surname = surname;
}
public String getSurname()
{
return surname;
}
public void setAge(int age)
{
this.age = age;
}
public int getAge()
{
Random random = new Random();
age = random.nextInt(30) + 20;
return age;
}
public static void main(String[] args)
{
try
{
File.record();
lista1.addAll(File.readingNames());
File.readingSurnames();
lista2.addAll(File.readingNames());
} catch (FileNotFoundException e)
{
} catch (IOException e)
{
}
}
}
3.
package ćw6;
public class Firma extends Pracownik
{
public static void main(String[] args)
{
Pracownik pracownik = new Pracownik();
System.out.println(pracownik.getName());
System.out.println(pracownik.getSurname());
System.out.println(pracownik.getAge());
}
}