我想做一种基本的Java语言...我遇到的问题是...输入输出文件只读了最后一行...我想做...如果用户输入输入一个ID ...计算机将读取具有相同ID的行...
import java.io.*;
import javax.swing.*;
import java.util.*;
public class BookingCinemaApp
{
public static void main(String []arg) throws IOException
{
try
{
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
FileReader reader = new FileReader("movie.txt");
BufferedReader in = new BufferedReader(reader);
FileWriter writer = new FileWriter("result.txt");
PrintWriter out = new PrintWriter( writer);
String inData = null;
BookingCinema[] customer = new BookingCinema[2];
int x = 0;
String name1,idno,hallnumber;
double tp;
for(x=0; x<customer.length;x++)
{
System.out.print("Please enter the date: ");
String d = sc1.nextLine();
System.out.print("Please enter the customer name: ");
String n = sc.nextLine();
System.out.print("Payment(Cash/Credit Card): ");
String p = sc1.nextLine();
System.out.print("\nPlease enter the movie ID: 1241 for Avatar 2 ");
System.out.print("\n 1242 for Dark Pheonix ");
System.out.print("\n 1243 for Polis Evo 2 ");
System.out.print("\n 1244 for Pengabdi Setan \n");
System.out.print("Please enter the movie ID: ");
String i = sc1.nextLine();
System.out.print("Please enter the genre of the movie: ");
String g = sc.nextLine();
boolean looping;
do
{
System.out.print("Please enter the seat: ");
String s = sc1.nextLine();
System.out.print("Please enter the quantity: ");
double q = sc.nextDouble();
System.out.print("Please enter age type (Adult/Student/Children): ");
String at = sc1.nextLine();
System.out.print("Please enter the seat type (C=Couple/S=Single): ");
char st1 = sc1.next().charAt(0);
while ((inData = in.readLine()) != null)
{
StringTokenizer st = new StringTokenizer(inData,",");
String id = st.nextToken();
String name = st.nextToken();
double ticketprice = Double.parseDouble(st.nextToken());
String hall = st.nextToken();
customer[x] =new BookingCinemaTicket(n,name,d,g,s,id,hall,st1,q,ticketprice,at,p);
}
System.out.print("Do you wish to continue(true/false)");
looping = sc.nextBoolean();
}while(looping==true);
if(i.equals("1241"))
{
System.out.print(customer[x].toString());
}
if(i.equals("1242"))
{
System.out.print(customer[x].toString());
}
if(i.equals("1243"))
{
System.out.print(customer[x].toString());
}
if(i.equals("1244"))
{
System.out.print(customer.toString());
}
}
in.close();
out.close();
}
catch(IOException io)
{
System.out.println(io.getMessage());
}
}
}