I'm trying to figure out how to implement code for writing in a text file, within the code that I have already established (with major help from a third party, as I am a Java newbie).
The way I would like it is to save the details of a customer or a booking, that has been registered or created, in a text file, as per below (first step - 1) Register a new Customer, or 2) Create a new Booking):
public static void main(String[] args) {
// setup and initialise the test data
List<Flight> availableFlights = generateTestFlights();
List<Hotel> availableHotels = generateTestHotels();
List<Excursion> availableExcursions = generateTestExcursions();
// create a new list of bookings
List<Booking> listOfReservedBookings = new ArrayList<>();
// initialise a new sales consultant which will operate on the behalf of the
// customer
SalesConsultant salesConsultant = new SalesConsultant();
// initialise the keyboard code
Scanner scanner = new Scanner(System.in);
// what will be displayed when executing application
System.out.println("Menu: ");
System.out.println("1) Register a new Customer");
System.out.println("2) Create a new Booking");
System.out.println("3) View available list of Flights");
System.out.println("4) View available list of Hotels");
System.out.println("5) View available list of Excursions");
System.out.println("6) View Reserved Bookings");
System.out.println("Please make your choice (type code number): ");
// displaying above written within brackets
String choice = scanner.nextLine();
// when "exit" choice is not showing
while (choice.equalsIgnoreCase("exit") == false) {
// register customer
if (choice.equalsIgnoreCase("1")) {
System.out.println("Registering a new customer: ");
// get the card ID for the new customer
System.out.println("Please insert Customer ID Card Number: ");
String cardID = scanner.nextLine();
// get the name of the new customer
System.out.println("Please insert Customer Name & Surname: ");
String name = scanner.nextLine();
// get the address of the new customer
System.out.println("Please insert Customer Address: ");
String address = scanner.nextLine();
// register customer
Customer customer = new Customer();
salesConsultant.registerCustomer(customer);
System.out.println("Customer has been registered successfully!");
}
Furthermore, would I need to create a new class for this, or can it be done through the main method?
Not sure if further code is needed.
Can someone kindly advise on this, please?
Many thanks in advance.