core java programming question

core java programming question

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

View Answers

December 17, 2010 at 11:52 AM

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









Related Tutorials/Questions & Answers:
core java programming question
core java programming question  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
Java Programming Question
Java Programming Question  write a program in java to show thread working with sleep and wait method   Hi Friend, Please visit the following links: Wait Method Sleep Method Thanks
Advertisements
programming question - Java Magazine
programming question  I have an SGVT map displaying on a phone emulator but then want to search for a given location on the map and display... tool. I need a java solution to this please
Java Programming Question
Java Programming Question  Write a program in Java to accept 10 different numbers an store it in text file.   Hi Friend, Try this: import java.io.*; import java.util.*; class AcceptNumbers{ public static void main
Java Programming Question
Java Programming Question  Write a program in Java to create a menu bar with the help of event handlers.   Hi Friend, Try this: import javax.swing.*; import java.awt.event.*; public class SwingMenuBar{ public
Assignment Question on java programming
Assignment Question on java programming  Can somone help me on this . Thx You are required to write a complete Java program for a simple grading system. At the beginning of the system, you need to input number of students
Java Programming Question
Java Programming Question  Write a program in Java to create student information form an submit detail in database.   Hi Friend, Try this: import java.awt.*; import java.sql.*; import javax.swing.*; import
programming question - Java Beginners
programming question  Create a class named Movie that can be used with your video rental business. The Movie class should track the Motion Picture Association of America (MPAA) rating (eg., Rated G, PG-13, R), ID Number
Java programming question - Java Beginners
Java programming question   Give the definition of a class named Doctor whose objects are records for a clinic's doctors. This class will be derived class of the class SalariedEmployee that is given below the question. A Doctor
Java programming question - Java Beginners
Java programming question  I want to write a program that converts temperatures from celsius to fahrenheit and vice versa. It also converts kilometers to miles and vice versa using "methods".  Hi Friend, Try
socket programming question
socket programming question   can you respond to me the multiple clients chat application java code and a server that manages the clients using the socket programming in java
socket programming question
socket programming question   can you respond to me the multiple clients chat application java code and a server that manages the clients using the socket programming in java
socket programming question
socket programming question   can you respond to me the multiple clients chat application java code and a server that manages the clients using the socket programming in java
Core Java Interview Question, Interview Question
Core Java Interview Question Page 24  .... Question: What is reflection in java Answer: Reflection allows Java code..., it is read only Question: What is the difference between Java Bean and Java
Core Java Interview Question, Interview Question
Core Java Interview Question   ....   Core Java Interview Question Page 1 How could Java... to a file?      Core Java Interview Question Page 2
Core Java Interview Question, Interview Question
Core Java Interview Question Page 29       Flow Control and exception Question: What... at the end of the body Question: When do you use continue and when do you use
Core Java Interview Question, Interview Question
Core Java Interview Question Page 9       Question: What are the uses of Serialization...(ts[i]); } } }ADS_TO_REPLACE_8 Question: What methods java providing for Thread
Core Java Interview Question, Interview Question
Core Java Interview Question Page 5       Question: What are different types... computer using such client/server Java technologies as RMI or socket programming
Core Java Interview Question, Interview Question
Core Java Interview Question Page 27       Modifiers Question: What are access modifiers... modifier then it is considered as Friendly Question: Can protected or friendly
Core Java Interview Question, Interview Question
Core Java Interview Question Page 14       Question: What is clipping? Answer: Clipping... that is implemented in a language other than Java. Question: Can
Core Java Interview Question, Interview Question
Core Java Interview Question Page 12       Question: What is a transient variable? Answer... collections of objects. Question: How does Java handle integer overflows
Core Java Interview Question, Interview Question
Core Java Interview Question Page 18       Question: Is &&= a valid Java... different sizes. Question: What advantage do Java's layout managers provide over
Core Java Interview Question, Interview Question
Core Java Interview Question Page 16  ..._TO_REPLACE_3 Question: How are Java source code files named? Answer: A Java source code... the .java extension. ADS_TO_REPLACE_4 Question: What is the relationship between
Core Java Interview Question, Interview Question
Core Java Interview Question Page 15  ... to the Java runtime system. Question: How many times may an object's finalize...: A program's main() method takes an argument of the String[] type. Question: Which Java
Core Java Interview Question, Interview Question
Core Java Interview Question Page 17       Question: What is the difference between... application window that can have a menu bar. ADS_TO_REPLACE_1 Question: Which class
Core Java Interview Question, Interview Question
Core Java Interview Question Page 32   ... Question: What is the ultimate ancestor of all java classes Answer: Object class is the ancestor of all the java classes Question: What
Core Java Interview Question, Interview Question
Core Java Interview Question Page 2   .... Question: What comes to mind when you hear about a young generation in Java... Question: How would you make a copy of an entire Java object with its state
Core Java Interview Question, Interview Question
Core Java Interview Question Page 21       Question: How are the elements of a GridLayout... and are laid out using the squares of a grid. ADS_TO_REPLACE_1 Question: What an I/O
Core Java Interview Question, Interview Question
Core Java Interview Question Page 13       Question: What is an Iterator interface? Answer.... ADS_TO_REPLACE_1 Question: What is the difference between the >> and >>
Core Java Interview Question, Interview Question
Core Java Interview Question Page 19       Question: What is the difference between static... variables take on unique values with each object instance. ADS_TO_REPLACE_1 Question
Core Java Interview Question, Interview Question
Core Java Interview Question Page 30       Objects and Classes Question: What's... while regular methods could be called many times. Question: What
core Java programming
core Java programming  Hi, Thanks for ur previous answers.... I need some of these answers also... Bharathi Indian Cuisine is a leading Indian...;TIME:HHMMSS;ITEM1:QTY:PRICE;ITEM2:PRICE2;] They are looking for a Java Program
Core Java Interview Question, Interview Question
Core Java Interview Question Page 20       Question: Name four Container classes. Answer..._TO_REPLACE_1 Question: What is the difference between a Choice and a List? Answer
Core Java Interview Question, Interview Question
Core Java Interview Question Page 22       Question: What is a compilation unit? Answer: A compilation unit is a Java source code file. ADS_TO_REPLACE_1 Question: What
Core Java Interview Question, Interview Question
Core Java Interview Question Page 23  ... group. ADS_TO_REPLACE_3 Question: What is a Java package and how is it used... that are loaded by a Java program. ADS_TO_REPLACE_5 Question: How does a try statement
Core Java Interview Question, Interview Question
Core Java Interview Question Page 26  ... explicitly Question: How is an argument passed in java, by copy... Question: What are different types of operators in java Answer: Uniary
Core Java Interview Question, Interview Question
Core Java Interview Question Page 25  ... function would be called. Question: Does java support virtual functions.... A Java program requires a JVM to run on a particular platform Question: Can
Core Java Interview Question, Interview Question
Core Java Interview Question Page 31       Threads Question: Where does java thread... The java language and virtual machine Question: What is the difference
Core Java Interview Question, Interview Question
Core Java Interview Question Page 28       Conversion Casting and Promotion Question: What... primitive types to be accessed as objects. Question: What are the four general
Core Java Interview Question, Interview Question
Core Java Interview Question Page 11       Question: What is serialization ?  Answer: Serialization is the process of writing complete state of java object
Core Java Interview Question, Interview Question
Core Java Interview Question Page 4       Question: What is the difference between checked and Unchecked Exceptions in Java ? Answer: All predefined exceptions in Java
Core Java Interview Question, Interview Question
Core Java Interview Question Page 7       Question: What... of java object into output stream, that stream can be file or byte array or stream
Core Java Interview Question, Interview Question
Core Java Interview Question Page 6       Question: How can i tell what state a thread...++){ System.out.println(ts[i]); } } } Question: What methods java providing
Core Java Interview Question, Interview Question
Core Java Interview Question Page 10       Question: What is the difference between notify..._TO_REPLACE_1 Question: What is synchronized keyword? In what situations you will Use
core java question - Java Interview Questions
core java question  I Have been asked the question in interview why we use constructors????? or what is the need of constructors?? or what is the utility of constructors????  to intialize the instance variabe we
Core java interview question, object creation.
Core java interview question, object creation.  How can we restrict to create objects for more than five? That means i want only 5 objects, how to restrict to create 6th objects
Core Java Programming - Java Beginners
Core Java Programming  Write a program in Java which initializes the starting date as your birthday and displays the date 90 days later in the format day name, month name, day, year   Hi friend, Code to solve
Core Java Programming - Java Beginners
Core Java Programming  Write a program in Java which generates a random number between 0 and 1. If the number generated is less than 0.5 then the program must print ?The Value is less than 0.5? and if the number generated
core question
core question  can we override or overload static methods   Hi Friend, We can overload static methods but we cannot override static methods.ADS_TO_REPLACE_1 Thanks
Java Programming
Java Programming  Hi, What is Java Programming? How I can learn Java Programming in one month? Thanks

Ads