Results 1 to 5 of 5

Thread: Output Problem

  1. #1
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Default Output Problem

    Purchase Items
    Order 458
    Invoice No

    Date Bill noBill DateDescriptionPurpose Qty Rate/unitAmt Remark
    12/05/05 152 11/06/08 abc xyz 12 15 250 Abcef
    11/05/05 2561 12/07/08 wtc prvn 25 2 2530 good
    12/05/05 8695 05/05/08 pen Abcd 12 21 24 Bad
    12/05/08 8956 06/05/08 Pencil Drawing 5 2 10 good

    Team member: 5 Authorised By: praveen
    Employee ID & Signature: 1478 praveen Signature
    Team Leader: abcd Accountant:ramu
    Received Date:12/05/08
    I am in need of
    12/05/05 152 11/06/08 abc xyz 12 15 250 Abcef
    11/05/05 2561 12/07/08 wtc prvn 25 2 2530 good
    12/05/05 8695 05/05/08 pen Abcd 12 21 24 Bad
    12/05/08 8956 06/05/08 Pencil Drawing 5 2 10 good
    But as per My code out put is this format
    12/05/05 152 11/06/08 abc xyz 12 15 250 Abcef
    11/05/05 2561 12/07/08 wtc prvn 25 2 2530 good
    12/05/05 8695 05/05/08 pen Abcd 12 21 24 Bad
    12/05/08 8956 06/05/08 Pencil Drawing 5 2 10 good
    Team member: 5 Authorised By: praveen
    Employee ID & Signature: 1478 praveen Signature
    Team Leader: abcd Accountant: ramu
    Received Date:12/05/08
    My code
    class purchasevchr {

    public static String inputFile = "purchase.txt";//Input file
    purchase pfr = new purchase();

    public void formatFile() {
    {

    try {
    FileInputStream in = new FileInputStream(inputFile);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;

    String regEx1 = "(\\d+/)";//date format is matched here
    Pattern regEx1P = Pattern.compile(regEx1);


    while ((strLine = br.readLine()) != null) {

    System.out.println(strLine);//line by line printing
    }

    } catch (Exception e) {
    System.out.println("Exception " + e);
    }
    }

    }

    public class sample{

    public static void main(String args[]){
    purchasevchr ob=new purchasevchr();
    ob.formatFile();
    }
    }
    i tried with the code
    /*


    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class expense1 {

    public static String inputFile = "expense.txt";

    public void formatFile() {

    try
    {
    FileInputStream in = new FileInputStream(inputFile);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;

    String regEx1 = "([0-9]/)";
    Pattern regEx1P = Pattern.compile(regEx1);

    System.out.println("Date " + "Bill " + "noBill" + "DateDescription" + " Purpose" +
    "Qty" + "Dist " + "Rate/unitAmt" + "Remark");

    while((strLine = br.readLine())!= null)
    {
    Matcher match1 = regEx1P.matcher(strLine);

    if (match1.find())
    {
    System.out.println(strLine);
    }

    //System.out.println(strLine);
    }
    }
    catch (Exception e)
    {
    System.out.println("Ouch! " + e);
    }
    }

    public static void main(String[] args) {
    expense1 exp = new expense1();
    exp.formatFile();

    }
    }
    output i am getting is:
    Date Bill noBillDateDescription PurposeQtyDist Rate/unitAmtRemark
    12/05/05 152 11/06/08 abc xyz 12 15 250 Abcef
    11/05/05 2561 12/07/08 wtc prvn 25 2 2530 good
    12/05/05 8695 05/05/08 pen Abcd 12 21 24 Bad
    12/05/08 8956 06/05/08 Pencil Drawing 5 2 10 good
    Received Date:12/05/08
    at the end i am also getting the "Received Date:12/05/08".i dnt want this

    can you help me in this..

    thanks in advance.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Default

    Thats wat i did but ..the issue with the Date Format..it is also taking the
    "Received Date:12/05/08"...even i ried with string split('' ");but no use..

    can you help me in this

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    If the way you have formated the date is fix, you can use following code.

    Java Code:
        public void formatFile() {
            try {
                FileInputStream in = new FileInputStream(inputFile);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String strLine;
    
                String regEx1 = "([0-9]/)";
                Pattern regEx1P = Pattern.compile(regEx1);
    
                System.out.println("Date " + "Bill " + "noBill" + "DateDescription" + " Purpose" +
                            "Qty" + "Dist " + "Rate/unitAmt" + "Remark");
    
                    while((strLine = br.readLine())!= null) {
                        Matcher match1 = regEx1P.matcher(strLine);
                        if (match1.find()) {
                            getFirstPart(strLine);
                        }
                        //System.out.println(strLine);
                    }
                }
            catch (Exception e) {
                System.out.println("Ouch! " + e);
            }
        }
    
        private void getFirstPart(String str) {
            if(str.charAt(2) == '/') {
                System.out.println(str);
            }
        }

Similar Threads

  1. No output displaying
    By Rgfirefly24 in forum New To Java
    Replies: 6
    Last Post: 04-27-2008, 08:37 PM
  2. Why the output is always zero
    By mehrotra.chitij in forum New To Java
    Replies: 12
    Last Post: 04-25-2008, 04:05 AM
  3. Output problem
    By jvasilj1 in forum New To Java
    Replies: 0
    Last Post: 01-31-2008, 06:39 PM
  4. output
    By Camden in forum New To Java
    Replies: 3
    Last Post: 12-01-2007, 10:34 PM
  5. No output shown
    By ai_2007 in forum Advanced Java
    Replies: 4
    Last Post: 07-10-2007, 09:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •