Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners core java programming question
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


suneetha
core java programming question
1 Answer(s)      4 years and a month ago
Posted in : Java Beginners


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


Advertisement
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
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
Advertisements
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
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
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
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
Core Java Interview Question, Interview Question
Core Java Interview Question Page 24       Question: Why do we need public static void main.... Question: What is reflection in java Answer: Reflection allows Java code
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
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, Interview Question
Core Java Interview Question Page 9       Question: What are the uses of Serialization... computer using such client/server Java technologies as RMI or socket programming
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 14       Question: What is clipping? Answer: Clipping... that is implemented in a language other than Java. Question: Can a for statement loop
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 5   ... Java technologies as RMI or socket programming. To "flatten"... enterprise java beans. To send objects between the servers in a cluster. Question
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. Question: What an I/O filter? Answer: An I
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. Question: Which class is extended by all
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. Question: What interface
Core Java Interview Question, Interview Question
Core Java Interview Question Page 23       Question: To what value is a variable... and interfaces that are loaded by a Java program. Question: How does a try statement
Core Java Interview Question, Interview Question
Core Java Interview Question Page 27       Modifiers Question: What are access modifiers... written in non java language Question: What are transient variables
Core Java Interview Question, Interview Question
Core Java Interview Question Page 18       Question: Is &&= a valid Java operator? Answer: No, it is not. Question: Name the eight primitive Java
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... mentions a shallow copy in Java? Answer: Object cloning. Question: If you're
Core Java Interview Question, Interview Question
Core Java Interview Question Page 26       Language Fundamentals Question: How... 64 - - Question: What types
Core Java Interview Question, Interview Question
Core Java Interview Question Page 16  ... implementation is deferred to a subclass. Question: How are Java source code files... and interfaces. Source code files use the .java extension. Question: What
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 15  ... is to provide access to the Java runtime system. Question: How many times may... takes an argument of the String[] type. Question: Which Java operator is right
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
 

 

 

DMCA.com