
How to write a java program to list the customer names arrived to a restuarant on a particular date in alphabetical order with arguments as 1 filename yymmdd cust

Hi Friend,
Try the following code:
import java.io.*;
import java.util.*;
class ResApplication
{
public static void main(String[] args) throws Exception
{
File f=new File("C:/Customer.txt");
BufferedWriter bw=new BufferedWriter(new FileWriter(f,true));
Scanner input=new Scanner(System.in);
for(int i=1;i<=10;i++){
System.out.print("Enter Customer Name: ");
String name=input.nextLine();
System.out.print("Enter Date(yyyy-mm-dd): ");
String date=input.nextLine();
bw.write(name+" "+date);
bw.newLine();
}
bw.close();
System.out.println();
System.out.print("Enter date to view the list of customers(yyyy-mm-dd): ");
String d=input.nextLine();
BufferedReader br=new BufferedReader(new FileReader(f));
String line="";
ArrayList list = new ArrayList();
ArrayList cusList=new ArrayList();
while ((line = br.readLine()) != null) {
list.add(line);
}
Iterator itr;
for (itr = list.iterator(); itr.hasNext();) {
String str = itr.next().toString();
String[] splitSt = str.split(" ");
String name = "", date = "";
for (int i = 0; i < splitSt.length; i++) {
name = splitSt[0];
date = splitSt[1];
if(date.equals(d)){
cusList.add(name);
}
}
}
Set set = new HashSet(cusList);
ArrayList l=new ArrayList(set);
Collections.sort(l);
for(int i=0;i<l.size();i++){
System.out.println(l.get(i).toString());
}
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.