Witam,
Mam mały problem, program , ktory napisalam sypie sie w jednej linijce(47) i zupelnie nie wiem dlaczego,
prosze o pomoc i z gory dziekuje:)
Witam,
Mam mały problem, program , ktory napisalam sypie sie w jednej linijce(47) i zupelnie nie wiem dlaczego,
prosze o pomoc i z gory dziekuje:)
public void ustalPunkty() {
for (int i = 0; i < iloscpytan; i++) {
ustalPunkty();
}
}
Nieskończona rekurencja.
Wybacz, ale jestem początkująca i nie rozumiem, o co chodzi. Próbowałam postępować zgodnie ze wskazówkami programu, ale wynik jest zawsze taki sam - program się kończy.
Funkcja wywołuje samą siebie w nieskończoność (a raczej aż nastąpi przepełnienie stosu i program się wysypie).
A moglbys mi podpowiedziec , jak zlikwidowac ten problem???
Nie wywoływać funkcji z samej siebie?
Nie wiem co ma robić funkcja ustalPunkty, ale to chyba widać, że obecnej formie nie robi nic poza zawieszeniem aplikacji:
Wiem, że ta funkcja wywołuje sama siebie, ale cały ten program jest prostą modyfikacją programu, którego robiłam wcześniej (pozamieniałam tylko zmienne) - wtedy wszystko działało. Nie mam zielonego pojęcia, jak to rozwiązać - podpowiedzi eclipse’a najczęściej wprowadzają jeszcze więcej błędów, a ja już nie mam pomysłu, co z tym dalej robić…
Masz drugą funkcję o podobnej nazwie, której nigdzie nie używasz, nie chodziło o wołanie ustalOceny?
Czyli problemem jest to, że mam dwa razy public void ustalPunkty, tak? Zmieniłam nazwę tej drugiej, ale ciągle nic z tego…
Zmień nazwę pliku ankieta.java na Ankieta.java i wstaw do niego dokładnie ten kod (importy są zbędne):
public class Ankieta {
private int iloscPytan;
private String[] pytania;
private int iloscOsob;
private String[] uczestnicy;
private int[][] iloscPunktow;
public Ankieta() {
System.out.print("Podaj ilosc pytan:");
iloscPytan = KeyboardReader.getIntFromKeyboard();
pytania = new String[iloscPytan];
for (int i = 0; i < iloscPytan; i++) {
System.out.print("Podaj tresc pytania nr " + (i + 1) + ":");
pytania[i] = KeyboardReader.getStringFromKeyboard();
}
System.out.println("");
System.out.print("Podaj ilosc osob:");
iloscOsob = KeyboardReader.getIntFromKeyboard();
uczestnicy = new String[iloscOsob];
for (int i = 0; i < iloscOsob; i++) {
System.out.print("Podaj imie i nazwisko ankietowanego uczestnika nr " + (i + 1) + ":");
uczestnicy[i] = KeyboardReader.getStringFromKeyboard();
}
System.out.println("");
iloscPunktow = new int[iloscPytan][iloscOsob];
}
public void ustalPunkty() {
for (int i = 0; i < iloscPytan; i++) {
ustalPunkty(i);
}
}
public void ustalPunkty(int nrPytania) {
System.out.println("Podaj liczbe przyznanych punktow dla pytania: \"" + pytania[nrPytania] + "\"");
for (int j = 0; j < iloscOsob; j++) {
System.out.print("Uczestnik " + uczestnicy[j] + ": ");
iloscPunktow[nrPytania][j] = KeyboardReader.getIntFromKeyboard();
}
System.out.println("");
}
private float suma() {
float suma = 0;
for (int i = 0; i < iloscPytan; i++) {
suma += suma(i);
}
return suma;
}
private float suma(int nrPytania) {
float suma = 0;
for (int i = 0; i < iloscOsob; i++) {
suma = suma + iloscPunktow[nrPytania][i];
}
return suma;
}
public float srednia() {
return suma() / (iloscPytan * iloscOsob);
}
public float srednia(int nrPytania) {
return suma(nrPytania) / iloscOsob;
}
public double wariancja() {
double wartosc = 0;
double suma = 0;
for (int i = 0; i < iloscPytan; i++) {
wartosc = wartosc + ((suma / (iloscPytan * iloscOsob))) * ((suma / (iloscPytan * iloscOsob))) * ((suma / (iloscPytan * iloscOsob))) * ((suma / (iloscPytan * iloscOsob)));
}
return ((suma / (iloscPytan * iloscOsob))) * ((suma / (iloscPytan * iloscOsob)));
}
public double odchylenie() {
double wartosc = 0;
double suma = 0;
for (int i = 0; i < iloscPytan; i++) {
wartosc = wartosc + ((suma / (iloscPytan * iloscOsob))) * ((suma / (iloscPytan * iloscOsob)));
}
return wartosc / iloscPytan;
}
public static void main(String[] args) {
Ankieta ankieta = new Ankieta();
ankieta.ustalPunkty();
System.out.println("Srednia: " + ankieta.srednia() + ".");
System.out.println("Wariancja: " + ankieta.wariancja() + ".");
System.out.println("Odchylenie standardowe: " + ankieta.odchylenie() + ".");
}
}
Kod poprawiłem i powinien Ci już teraz działać (nie poprawiłem jedynie metod wariancja i odchylenie, docelowo metody te mają korzystać z tych wzorów: http://matematyka.pisz.pl/strona/1028.html ?). Zmodyfikowałem też metodę średnia. Teraz można obliczać średnia ilość punktów dla wszystkich pytań oraz wybranego pytania.
Celem konstruktora jest inicjalizacja obiektu, ustawienie wartości pól, utworzenie obiektów składowych. A nie wykonywanie operacji wejścia/wyjścia, całość tych operacji powinna być wyniesiona do metody.
Do czego w ogóle służą pola iloscPytan i ilostOsob? Tablice w Javie nie mają czegoś takiego jak lehgth?
Poza tym, skoro już piszemy w Javie, to wypadałoby to zrobić obiektowo. Dlaczego są używane oddzielne tablice na treść pytań i liczbę (liczba, bo punkty są policzalne) punktów? Zamiast tego powinna być klasa Pytanie, z polami: treść i liczbaPunktów. Wypadałoby przy definiowaniu pytania jednocześnie podawać jego treść i liczbę punktów, a nie rozbijać tego na dwie operacje. A już tak całkiem fajnie by było, gdyby do operacji wejścia/wyjścia służyła oddzielna klasa, która tworzy obiekt Ankiety zawierający tablicę Pytań, a wszelkie obliczenia statystyczne powinny być w jeszcze innej klasie.
W ramach rozrywki trochę podłubałem w tym kodzie. Wrzucam co z tego wyszło. Może Ci się przyda.
Consts.java
public class Consts {
public static String _SURVEYS_FILE_NAME = "surveys.ser";
public static String _PARTICIPANTS_FILE_NAME = "participants.ser";
}
KeyboardReader.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class KeyboardReader {
public static String getStringFromKeyboard() {
BufferedReader reader = null;
String result = "";
try {
reader = new BufferedReader(new InputStreamReader(System.in));
result = reader.readLine();
} catch (IOException ex) {
}
return result;
}
public static int getIntFromKeyboard() {
BufferedReader reader = null;
int result = 0;
try {
reader = new BufferedReader(new InputStreamReader(System.in));
result = Integer.parseInt(reader.readLine());
} catch (IOException ex) {
}
return result;
}
public static char getCharFromKeyboard() {
BufferedReader reader = null;
char result = ' ';
try {
reader = new BufferedReader(new InputStreamReader(System.in));
result = (char) reader.read();
} catch (IOException ex) {
}
return result;
}
}
Participant.java
import java.io.Serializable;
public class Participant implements Serializable {
private String name;
private Surveys surveys;
public Participant() {
this.name = "";
this.surveys = new Surveys();
}
public Participant(String name) {
this.name = name;
this.surveys = new Surveys();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Surveys getSurveys() {
return surveys;
}
public void setSurveys(Surveys surveys) {
this.surveys = surveys.copySurveys();
}
public void prepareParticipant() {
this.prepareParticipant(null);
}
public void prepareParticipant(Surveys surveys) {
System.out.print("Podaj imię i nazwisko: ");
this.setName(KeyboardReader.getStringFromKeyboard());
if (surveys != null) {
for (int i = 0; i < surveys.size(); i++) {
if (!this.getSurveys().contains(surveys.get(i).getName())) {
this.getSurveys().add(surveys.get(i).copySurvey());
}
}
}
}
public void fillSurveys() {
System.out.println("Uczestnik: \"" + this.getName() + "\"");
for (int i = 0; i < this.getSurveys().size(); i++) {
System.out.println("");
System.out.println("Ankieta: \"" + this.getSurveys().get(i).getName() + "\"");
if (!this.getSurveys().get(i).isFilled()) {
for (int j = 0; j < this.getSurveys().get(i).getQuestions().size(); j++) {
System.out.print("Pytanie \"" + this.getSurveys().get(i).getQuestions().get(j).getText() + "\": ");
this.getSurveys().get(i).getQuestions().get(j).setScore(KeyboardReader.getIntFromKeyboard());
}
this.getSurveys().get(i).setFilled(true);
} else {
for (int j = 0; j < this.getSurveys().get(i).getQuestions().size(); j++) {
System.out.print("Pytanie \"" + this.getSurveys().get(i).getQuestions().get(j).getText() + "\": ");
System.out.println(this.getSurveys().get(i).getQuestions().get(j).getScore());
}
}
}
}
}
Participants.java
import java.util.ArrayList;
import java.io.Serializable;
public class Participants extends ArrayList implements Serializable {
public Participants() {
super();
}
public void prepareParticipants() {
this.prepareParticipants(null);
}
public void prepareParticipants(Surveys surveys) {
Participant participant = null;
boolean prepare = false;
int i = 1;
System.out.println("");
System.out.println(" ******************************Dodawanie uczestników ankiet*******************************");
prepare = this.askIfMakeNewParticipant(false);
if (prepare) {
do {
System.out.println("");
System.out.print("[" + i + "] ");
participant = new Participant();
participant.prepareParticipant(surveys);
this.add(participant);
System.out.println("");
prepare = this.askIfMakeNewParticipant(true);
i++;
} while (prepare);
}
System.out.println("");
System.out.println(" ******************************Usuwanie uczestników ankiet********************************");
prepare = this.askIfDeleteExistingParticipant(false);
if (prepare) {
do {
System.out.println("");
i = this.askWhichParticipantToDelete();
if (i != -1) {
this.remove(i);
System.out.println("");
prepare = this.askIfDeleteExistingParticipant(true);
} else {
prepare = false;
}
} while (prepare);
}
}
private boolean askIfMakeNewParticipant(boolean next) {
String question = "Czy chcesz dodać " + (next ? "kolejnego " : "") + "uczestnika ankiet [t lub n]? ";
return this.askIf(question);
}
private boolean askIfDeleteExistingParticipant(boolean next) {
String question = "Czy chcesz usunąć " + (next ? "kolejnego " : "") + "uczestnika ankiet [t lub n]? ";
return this.askIf(question);
}
private boolean askIf(String question) {
char c = 'n';
do {
System.out.print(question);
c = KeyboardReader.getCharFromKeyboard();
} while (!(c == 'n' || c == 't'));
if (c == 't') {
return true;
}
return false;
}
private int askWhichParticipantToDelete() {
int result = -1;
System.out.println("Aktualni uczestnicy:");
System.out.println("[0] Anuluj");
for (int i = 0; i < this.size(); i++) {
System.out.println("[" + (i + 1) + "] " + this.get(i).getName());
}
do {
System.out.print("Podaj numer uczestnika do usunięcia: ");
result = KeyboardReader.getIntFromKeyboard();
} while (!(result >= 0 && result <= this.size()));
return result - 1;
}
public void displayParticipants() {
System.out.println("");
System.out.println(" *****************************Wyświetlanie uczestników ankiet*****************************");
if (this.size() == 0) {
System.out.println("Brak uczestników do wyświetlenia.");
} else {
System.out.println("Aktualni uczestnicy:");
for (int i = 0; i < this.size(); i++) {
System.out.println("[" + (i + 1) + "] " + this.get(i).getName());
}
}
}
public void fillSurveys() {
System.out.println("");
System.out.println(" *************************Przyznawanie punktów uczestnikom ankiet*************************");
for (int i = 0; i < this.size(); i++) {
System.out.println("");
System.out.print("[" + (i + 1) + "] ");
this.get(i).fillSurveys();
}
}
public boolean serialize() {
return this.serialize(Consts._PARTICIPANTS_FILE_NAME);
}
public boolean serialize(String filePath) {
boolean result = true;
System.out.println("");
System.out.println(" *********************************Zapisywanie uczestników*********************************");
try {
Serialization.serialize(this, filePath);
} catch (Exception e) {
result = false;
}
if (result) {
System.out.println("Informacje o uczestnikach ankiet zostały zapisane w pliku " + filePath);
} else {
System.out.println("Informacje o uczestnikach ankiet nie zostały zapisane w pliku " + filePath);
}
return result;
}
public boolean deserialize() {
return this.deserialize(Consts._PARTICIPANTS_FILE_NAME);
}
public boolean deserialize(String filePath) {
boolean result = true;
Participants participants = null;
System.out.println("");
System.out.println(" *********************************Wczytywanie uczestników*********************************");
try {
participants = (Participants) Serialization.deserialize(filePath);
if (participants != null) {
for (int i = 0; i < participants.size(); i++) {
this.add(participants.get(i));
}
}
} catch (Exception e) {
result = false;
}
if (result) {
System.out.println("Informacje o uczestnikach ankiet zostały odczytane z pliku " + filePath);
} else {
System.out.println("Informacje o uczestnikach ankiet nie zostały odczytane z pliku " + filePath);
}
return result;
}
}
Program.java
public class Program {
public static void main(String[] args) {
Surveys surveys = new Surveys();
Participants participants = new Participants();
SurveyCalculator surveyCalculator = new SurveyCalculator();
boolean surveysDeserialized = surveys.deserialize();
boolean participantsDeserialized = participants.deserialize();
if(!(surveysDeserialized && participantsDeserialized)) {
surveys = new Surveys();
participants = new Participants();
}
surveys.prepareSurveys();
surveys.displaySurveys();
participants.prepareParticipants(surveys);
participants.displayParticipants();
if (surveys.size() != 0 && participants.size() != 0) {
participants.fillSurveys();
surveyCalculator.Calculate(surveys, participants);
}
if (surveys.serialize()) {
participants.serialize();
}
}
}
Question.java
import java.io.Serializable;
public class Question implements Serializable {
private String text;
private double score;
public Question(String text) {
this.text = text;
}
public Question(String text, double score) {
this.text = text;
this.score = score;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}
Questions.java
import java.util.ArrayList;
import java.io.Serializable;
public class Questions extends ArrayList implements Serializable {
public Questions() {
super();
}
}
Serialization.java
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
public class Serialization {
public static void serialize(Object o, String filePath) throws FileNotFoundException, IOException {
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try {
fos = new FileOutputStream(filePath);
oos = new ObjectOutputStream(fos);
oos.writeObject(o);
} catch (FileNotFoundException e) {
throw e;
} catch (IOException e) {
throw e;
} finally {
try {
if (oos != null) {
oos.close();
}
} catch (IOException e) {
}
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
}
}
}
public static Object deserialize(String filePath) throws FileNotFoundException, IOException, ClassNotFoundException {
Object result = null;
FileInputStream fis = null;
ObjectInputStream ois = null;
try {
fis = new FileInputStream(filePath);
ois = new ObjectInputStream(fis);
result = ois.readObject();
} catch (FileNotFoundException e) {
throw e;
} catch (IOException e) {
throw e;
} catch (ClassNotFoundException e) {
throw e;
} finally {
try {
if (ois != null) {
ois.close();
}
} catch (IOException e) {
}
try {
if (fis != null) {
fis.close();
}
} catch (IOException e) {
}
}
return result;
}
}
Survey.java
import java.io.Serializable;
public class Survey implements Serializable {
private String name;
private Questions questions;
private boolean filled;
public Survey() {
this.name = "";
this.questions = new Questions();
this.filled = false;
}
public Survey(String name) {
this.name = name;
this.questions = new Questions();
this.filled = false;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Questions getQuestions() {
return questions;
}
public void setQuestions(Questions questions) {
this.questions = questions;
}
public boolean isFilled() {
return filled;
}
public void setFilled(boolean filled) {
this.filled = filled;
}
public void prepareSurvey() {
int questionsCount = 0;
System.out.print("Podaj nazwę: ");
this.setName(KeyboardReader.getStringFromKeyboard());
System.out.print("Podaj ilość pytań: ");
questionsCount = KeyboardReader.getIntFromKeyboard();
for (int i = 0; i < questionsCount; i++) {
System.out.print("Podaj treść pytania nr " + (i + 1) + ": ");
this.getQuestions().add(new Question(KeyboardReader.getStringFromKeyboard()));
}
}
public Survey copySurvey() {
Survey surveyCopy = new Survey(this.getName());
Question questionCopy = null;
for (int i = 0; i < this.getQuestions().size(); i++) {
questionCopy = new Question(this.getQuestions().get(i).getText(),
this.getQuestions().get(i).getScore());
surveyCopy.getQuestions().add(questionCopy);
}
surveyCopy.setFilled(this.isFilled());
return surveyCopy;
}
}
SurveyCalculator.java
public class SurveyCalculator {
private Survey survey;
private Participants participants;
public SurveyCalculator() {
this.survey = null;
this.participants = null;
}
private double sum() {
double sum = 0;
for (int i = 0; i < this.participants.size(); i++) {
sum += sum(i, true);
}
return sum;
}
private double sum(int index, boolean scorePerUser) {
double sum = 0;
int count = scorePerUser ? this.survey.getQuestions().size() : this.participants.size();
int k = 0;
int l = 0;
for (int i = 0; i < count; i++) {
k = scorePerUser ? index : i;
l = scorePerUser ? i : index;
sum += this.participants.get(k).getSurveys().get(this.survey.getName()).getQuestions().get(l).getScore();
}
return sum;
}
private double arithmeticMean() {
double bottom = this.participants.size() * this.survey.getQuestions().size();
return this.sum() / bottom;
}
private double arithmeticMean(int index, boolean scorePerUser) {
double bottom = scorePerUser ? this.survey.getQuestions().size() : this.participants.size();
return this.sum(index, scorePerUser) / bottom;
}
private double variance(int index, boolean scorePerUser) {
double value = 0;
double arithmeticMean = this.arithmeticMean(index, scorePerUser);
int count = scorePerUser ? this.survey.getQuestions().size() : this.participants.size();
int k = 0;
int l = 0;
for (int i = 0; i < count; i++) {
k = scorePerUser ? index : i;
l = scorePerUser ? i : index;
value += Math.pow(this.participants.get(k).
getSurveys().get(this.survey.getName()).
getQuestions().get(l).getScore() - arithmeticMean, 2.0);
}
return value / count;
}
private double standardDeviation(int index, boolean scorePerUser) {
return Math.pow(this.variance(index, scorePerUser), 0.5);
}
private void displayResult() {
System.out.println("Ankieta: \"" + this.survey.getName() + "\"");
System.out.println("");
System.out.println("[a] z podziałem na uczestników");
System.out.println("");
this.displayResult(true);
System.out.println("[b] z podziałem na pytania");
System.out.println("");
this.displayResult(false);
}
private void displayResult(boolean scorePerUser) {
int count = scorePerUser ? this.participants.size() : this.survey.getQuestions().size();
String message = "";
for (int i = 0; i < count; i++) {
if (scorePerUser) {
message = "Uczestnik: \"" + this.participants.get(i).getName() + "\"";
} else {
message = "Pytanie: \"" + this.survey.getQuestions().get(i).getText() + "\"";
}
System.out.println(message);
System.out.println("Średnia arytmetyczna: " + this.arithmeticMean(i, scorePerUser) + ".");
System.out.println("Wariancja: " + this.variance(i, scorePerUser) + ".");
System.out.println("Odchylenie standardowe: " + this.standardDeviation(i, scorePerUser) + ".");
System.out.println("");
}
}
public void Calculate(Survey survey, Participants participants) {
this.survey = survey;
this.participants = participants;
this.displayResult();
}
public void Calculate(Surveys surveys, Participants participants) {
System.out.println("");
System.out.println(" **********************************Wykonywanie obliczeń***********************************");
for (int i = 0; i < surveys.size(); i++) {
System.out.print("[" + (i + 1) + "] ");
this.Calculate(surveys.get(i), participants);
}
}
}
Surveys.java
import java.util.ArrayList;
import java.io.Serializable;
public class Surveys extends ArrayList implements Serializable {
public Surveys() {
super();
}
public void prepareSurveys() {
Survey survey = null;
boolean prepare = false;
int i = 1;
System.out.println("");
System.out.println(" ************************************Tworzenie ankiet*************************************");
prepare = this.askIfMakeNewSurvey(false);
if (prepare) {
do {
System.out.println("");
System.out.print("[" + i + "] ");
survey = new Survey();
survey.prepareSurvey();
if (this.contains(survey.getName())) {
System.out.println("Ankieta o podanej nazwie już istnieje. Ankieta nie została utworzona.");
} else {
this.add(survey);
System.out.println("Ankieta została utworzona.");
}
System.out.println("");
prepare = this.askIfMakeNewSurvey(true);
i++;
} while (prepare);
}
System.out.println("");
System.out.println(" ************************************Usuwanie ankiet**************************************");
prepare = this.askIfDeleteExistingSurvey(false);
if (prepare) {
do {
System.out.println("");
i = this.askWhichSurveyToDelete();
if (i != -1) {
this.remove(i);
System.out.println("Ankieta została usunięta.");
System.out.println("");
prepare = this.askIfDeleteExistingSurvey(true);
} else {
prepare = false;
}
} while (prepare);
}
}
private int askWhichSurveyToDelete() {
int result = -1;
System.out.println("Dostępne ankiety:");
System.out.println("[0] Anuluj");
for (int i = 0; i < this.size(); i++) {
System.out.println("[" + (i + 1) + "] " + this.get(i).getName());
}
do {
System.out.print("Podaj numer ankiety do usunięcia: ");
result = KeyboardReader.getIntFromKeyboard();
} while (!(result >= 0 && result <= this.size()));
return result - 1;
}
private boolean askIfMakeNewSurvey(boolean next) {
String question = "Czy chcesz przygotować " + (next ? "następną " : "") + "ankietę [t lub n]? ";
return this.askIf(question);
}
private boolean askIfDeleteExistingSurvey(boolean next) {
String question = "Czy chcesz usunąć " + (next ? "następną " : "") + "ankietę [t lub n]? ";
return this.askIf(question);
}
private boolean askIf(String question) {
char c = 'n';
do {
System.out.print(question);
c = KeyboardReader.getCharFromKeyboard();
} while (!(c == 'n' || c == 't'));
if (c == 't') {
return true;
}
return false;
}
public void displaySurveys() {
System.out.println("");
System.out.println(" ***********************************Wyświetlanie ankiet***********************************");
if (this.size() == 0) {
System.out.println("Brak ankiet do wyświetlenia.");
} else {
System.out.println("Dostępne ankiety:");
for (int i = 0; i < this.size(); i++) {
System.out.println("[" + (i + 1) + "] " + this.get(i).getName());
}
}
}
public Surveys copySurveys() {
Surveys surveysCopy = new Surveys();
for (int i = 0; i < this.size(); i++) {
surveysCopy.add(this.get(i).copySurvey());
}
return surveysCopy;
}
public Survey get(String name) {
for (int i = 0; i < this.size(); i++) {
if (this.get(i).getName().toLowerCase().compareTo(name.toLowerCase()) == 0) {
return this.get(i);
}
}
return null;
}
public boolean contains(String name) {
for (int i = 0; i < this.size(); i++) {
if (this.get(i).getName().toLowerCase().compareTo(name.toLowerCase()) == 0) {
return true;
}
}
return false;
}
public boolean serialize() {
return this.serialize(Consts._SURVEYS_FILE_NAME);
}
public boolean serialize(String filePath) {
boolean result = true;
System.out.println("");
System.out.println(" ***********************************Zapisywanie ankiet************************************");
try {
Serialization.serialize(this, filePath);
} catch (Exception e) {
result = false;
}
if (result) {
System.out.println("Informacje o ankietach zostały zapisane w pliku " + filePath);
} else {
System.out.println("Informacje o ankietach nie zostały zapisane w pliku " + filePath);
}
return result;
}
public boolean deserialize() {
return this.deserialize(Consts._SURVEYS_FILE_NAME);
}
public boolean deserialize(String filePath) {
boolean result = true;
Surveys surveys = null;
System.out.println("");
System.out.println(" ***********************************Wczytywanie ankiet************************************");
try {
surveys = (Surveys) Serialization.deserialize(filePath);
if (surveys != null) {
for (int i = 0; i < surveys.size(); i++) {
this.add(surveys.get(i));
}
}
} catch (Exception e) {
result = false;
}
if (result) {
System.out.println("Informacje o ankietach zostały odczytane z pliku " + filePath);
} else {
System.out.println("Informacje o ankietach nie zostały odczytane z pliku " + filePath);
}
return result;
}
}