Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: i need help with java source code

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    My Mood
    Dead
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default i need help with java source code

    Scenario

    A local company “Aaron Technology Sdn Bhd” has encounters a problem on providing their customer
    with a proper receipt for the purchase item. This is because all the information is store in the text file
    called customer.txt which is hardly understand by their customer. The sample file is shown below:

    Text file format: <Receipt No.> <Payment Term> <Customer Name> <Item No.> <Item Name> <Quantity> <Price>
    Therefore, your task is to generate the customer receipt in the form of formatted text file and save it as
    receipts.txt. The output of the file is shown below:

    Develop java program that can be use to extract the data from “customer.txt” file and transform it to
    become a readable receipt format as shown above

    sample output: on attachment
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: i need help with java source code

    Please post the code here that you are having problems with and the questions you have about the problems.

    Please post all information about the problem on the forum. No attachments.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    My Mood
    Dead
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: i need help with java source code

    import java.util.*;
    import java.io.*;
    import java.text.*;
    public class Beta
    {
     
        public static void main(String[] args) throws FileNotFoundException
        {
            String Customer, ItemNo, ItemName;
            int Quantity, ReceiptNo;
            double Total, GST, Price, Price2;
            String CASH = "";
            String CREDIT = "";
              String Payment = "";
            String Payment;
            Date d = new Date();
     
            SimpleDateFormat dateFormat = new SimpleDateFormat("d/MMM/yyyy");
     
            Scanner readFile = new Scanner (new FileReader("E:\\New folder (2)\\customer.txt"));
     
            PrintWriter writeFile = new PrintWriter("E:\\New folder (2)\\Receiptmizan1.txt");
     
            while(readFile.hasNext())
            {
                Payment = "CREDIT";
                ReceiptNo = readFile.nextInt();
                Payment = readFile.next();
                Customer = readFile.next();
                ItemNo = readFile.next();
                ItemName = readFile.next();
                Quantity = readFile.nextInt();
                Price = readFile.nextDouble();
     
                System.out.println(Payment2);
                System.out.println(Payment);
     
                if (Payment.equals(Payment2)) 
                {
                    System.out.println("The strings are equal");
                } else
                {
                    System.out.println("The strings are unequal");
                }
     
                DecimalFormat f = new DecimalFormat("#.00");
                System.out.println(f.format(Price));
     
                Price2 = Price;
     
                if (Payment.equals(Payment2))
                {
                    Price = Price * 90/100;
                }
     
                writeFile.println();
                writeFile.println();
                writeFile.println("     Aaron Technology Sdn Bhd            ");
                writeFile.println();
                writeFile.println("      Bangunan Aziz dan Anak-anak          ");
                writeFile.println("      Block 'A' Tingkat 1, No.4           ");
                writeFile.println("      Jalan Adam, Simpang 234            ");
                writeFile.println("       AST-Beyonf, Kuala Hawa             ");
                writeFile.println("         Brunei CH134                   ");
                writeFile.println();
                writeFile.println();
                writeFile.println();
                writeFile.println("         RECEIPT 00" + ReceiptNo + "" );
                writeFile.println(" ==================================== ");
                writeFile.printf("     Customer Name: %s %n"             ,Customer  );
                writeFile.println("     Date : "                  + dateFormat.format(d));
                writeFile.println("     Payment term : "                  +Payment);
     
                if (Payment.equals(Payment))
                {
                    writeFile.println("     Discount rate = 10%");
                }
     
                writeFile.println("     Item No. : " + ItemNo       );
                writeFile.println(" ===================================== ");
                writeFile.println("         " + ItemName );
                Total = Price  Quantity;
                writeFile.println("         " + Quantity + " x " + f.format(Price2) + " $" + f.format(Total) + "");
                writeFile.println("        Total Amount");
                GST = Total * 105/100;
     
                writeFile.println(" Total include GST of 5% : " + f.format(GST) + "");
                writeFile.println();
                writeFile.println("---------------CUT HERE---------------");
            }    
            writeFile.println();
            writeFile.println("Receipt.txt is successfully created");
            readFile.close();
            writeFile.close();
        }
    }


    --- Update ---

    fail to compile and print the output txt file need help plzz.....
    here are the customer txt file:
    001 CASH Ahmad PD80512 Pendrive-8GB 2 65
    002 CASH Raymond CP71112 Desktop-i7 1 1765
    003 CREDIT Syukri PD40112 Pendrive-4GB 10 20
    004 CASH Halimah PD40112 Pendrive-4GB 10 20
    005 CREDIT Osman OMW0511 Optical-Mouse(Wireless) 2 38.50
    006 CREDIT Huzaimi MWS0211 Monitor-27"inch(LED) 1 260
    007 CASH Maya KBW0610 Keyboard(Wireless) 5 35.70
    008 CASH Chen MSU0309 Mini-Speaker(USB) 1 10.60
    009 CREDIT Krishnan IPM1112 Ipad-Mini(WIFI) 2 680
    010 CREDIT Nuraqmal SGN1212 Galaxy-Note(10.1) 1 799.90

  4. #4
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    My Mood
    Dead
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: i need help with java source code

    Untitled.jpgfrom the question... and how to make the txt output print.. in middle as in the picture

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: i need help with java source code

    Please post your questions about the code.
    If you are getting errors, copy the full text of the error messages and post them.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: i need help with java source code

    Hi Daruga , i found the mistakes
    wrong: 1
    String Payment = "";
    String Payment

    in the main method don't declare two variables with same name and should be initialize before using. like
    pls change:
    String Payment="";
    String Payment1="";


    wrong: 2

    Total = Price Quantity;

    pls change :
    Total =Price * Quality;

    modified code:
    ------------------
    >>>>>>>>>>> Code removed
    Last edited by Norm; January 9th, 2013 at 07:46 AM. Reason: spoonfed code removed

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: i need help with java source code

    @basha2013 Please don't do OPs work for him. See:
    http://www.javaprogrammingforums.com...n-feeding.html
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to implement YAHTZEE game in java using switch statements?
    By SeriousJavaHelp in forum Object Oriented Programming
    Replies: 1
    Last Post: October 18th, 2012, 07:46 AM
  2. Note pad source code open instead of executing java program?
    By clalrama in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 26th, 2012, 06:11 PM
  3. Java Source Code to UML Diagrams in NetBeans
    By sarkuzi in forum Threads
    Replies: 3
    Last Post: February 7th, 2012, 11:34 AM
  4. Source Code to Implement Circular Queue in Java
    By rainbow9 in forum Java Programming Tutorials
    Replies: 0
    Last Post: August 20th, 2011, 02:30 AM
  5. Implementing HTML tags in Java Source Code
    By bookface in forum Java Theory & Questions
    Replies: 4
    Last Post: March 19th, 2010, 09:29 PM