From 1b9bbe383c1c9c46a4d083c15fcd6e2a7d69fa6b Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Thu, 10 Feb 2022 01:28:50 +0100 Subject: [PATCH] implemented AircraftRepository methods --- .../ci/exam/project/AircraftRepository.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/hs/fulda/de/ci/exam/project/AircraftRepository.java diff --git a/src/main/java/hs/fulda/de/ci/exam/project/AircraftRepository.java b/src/main/java/hs/fulda/de/ci/exam/project/AircraftRepository.java new file mode 100644 index 0000000..241363f --- /dev/null +++ b/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 ""; + } +}