|
|
@ -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 ""; |
|
|
|
} |
|
|
|
} |