Browse Source

implemented AircraftRepository methods

feature-pr-Admin
Sona Markosyan 2 years ago
parent
commit
1b9bbe383c
  1. 31
      src/main/java/hs/fulda/de/ci/exam/project/AircraftRepository.java

31
src/main/java/hs/fulda/de/ci/exam/project/AircraftRepository.java

@ -0,0 +1,31 @@
package hs.fulda.de.ci.exam.project;
import java.io.*;
import java.util.Scanner;
public class AircraftRepository {
boolean save(Aircraft aircraft) throws IOException {
FileWriter fw = new FileWriter("aircraft_list.txt", true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(aircraft.toString());
bw.newLine();
bw.close();
return true;
};
String findAircraftByAircraftNumber(String AircraftName){
File file = new File("aircraft_list.txt");
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if(line.matches("(.*)"+AircraftName+"(.*)")) {
return line;
}
}
} catch(FileNotFoundException e) {
System.out.println("There are no aircrafts added yet. Please add a aircraft first");
}
return "";
}
}
Loading…
Cancel
Save