Question: Subject: java programming Below is the code for read the file. Please help me to make code for write the data based on THE QUESTION.

Subject: java programming

Below is the code for read the file. Please help me to make code for write the data based on THE QUESTION. Please put array for the data just what i did in the code below. Match it with my code. Thank you.

import java.io.*;

import java.util.Scanner;

public class GuestInfo {

public static void main(String[] args) {

try {

// Open the input file

File file = new File("guest.txt");

Scanner sc = new Scanner(file);

int breakfastCount = 0;

// Read each line of the file

while (sc.hasNextLine()) {

String line = sc.nextLine();

String[] guestInfo = line.split(" ");

// Display the guest information

System.out.println("Room No: " + guestInfo[0]);

System.out.println("Guest Name: " + guestInfo[1] + " " + guestInfo[2]);

System.out.println("Type: " + guestInfo[3]);

System.out.println("Breakfast: " + guestInfo[4]);

System.out.println("Price: " + guestInfo[5]);

System.out.println("Date of Stay: " + guestInfo[6]);

System.out.println();

// Count the number of guests who opt for breakfast

if (guestInfo[4].equals("Yes")) {

breakfastCount++;

}

}

// Display the number of guests who opt for breakfast

System.out.println("Guests with a \"Yes\" for breakfast: " + breakfastCount);

// Close the input file

sc.close();

} catch (FileNotFoundException e) {

System.out.println("Error: Unable to open file.");

}

}

}

Subject: java programming Below is the code for read the file. Please

The following data contains information of guest staying at Hotel B stored in a text file named guest.txt. Each line contains the guest's room no, the guest's name, the type of room, breakfast option, total price for room and date of stay. Write a Java program with a method that does the following: i) Reads the input file guest.txt and display the information onto the screen ii) Count the number of guests who opt "Yes" for breakfast in the file and display the result onto the screen. Input file (guest.txt) 1501 Salina Mohd Sani Deluxe Yes 240 16-17/01/23 812 Abdullah Muhd Ismail Family No 3502425/01/23 1105 Chan Lee Wei Suite Yes 485 23-25/01/23 210 Mohd Firdhaus Hussin Executive Yes 6202224/01/23 608 David Anand Ravi Executive Yes 8451417/02/23 1209 Timothy Lee Anderson Single No 1801819/02/23 Sample Output Guests with a "Yes" for breakfast: 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!