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 10 of 10

Thread: Cannot find symbol writefile

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

    Post Cannot find symbol writefile

    import java.util.*;
    import java.io.*;
    import java.util.Arrays;
    public class Assignment2
    {
    public static void main(String[]args ) throws FileNotFoundException
    {
        String[] A= {"Aaron Technology Sdn Bhd", "Bagunan Aziz dan Anak-anak"//0 1
                    , "Blok'A', Tingkat 1, No.4","Jalan Adam, Simpang 234",// 2 3
                    "AST-Beyond, Kuala Hawa", "Brunie CH134", "Receipt No",// 4 5 6
                      "Customer Name :", "Payment Term :", "Item No. : ",// 7 8 9
                 "-----------------------------"," ","Total Include GST of 5% :", //10 11 12
                "Total Amount", // 13
            "------------------------------------Cut Here ---------------------------------"}; // 14
         String PaymentTerm, CustomerName, ItemNo , ItemName ;
     
        double x=0.00,Quantity,Price = 1 , Tax =0.05 , CREDIT =0.1 , ReceiptNo ;            
     
       Scanner readFile = new Scanner(new FileReader("C:\\Users\\user\\Documents\\DIT MKJB\\Programming Java\\customer.txt"));
     
       PrintWriter writefile = new PrintWriter("C:\\Users\\user\\Desktop\\receipts.txt");
     
        while(readFile.hasNext())
        {
        ReceiptNo = readFile.nextDouble();
        PaymentTerm = readFile.next();
        CustomerName = readFile.next();
        ItemNo = readFile.next();
        ItemName = readFile.next();
        Quantity = readFile.nextDouble();
        Price = readFile.nextDouble();
        CREDIT = readFile.nextDouble();
     
        writeFile.printf("%53s \n%54s \n%53s \n%52s \n%52s \n%46s\n",A[0],A[1],A[2],A[3],A[4],A[5]);
     
     
          writeFile.println(); // RECEIPT NO 001
          writeFile.printf("%43s %s \n%55s \n%41s Ahmad \n%40s CASH \n%37s PD80512 \n%55s \n"
                           ,A[6],ReceiptNo,A[10],A[7],A[8],A[9],A[10]);
                           x = Quantity * Price;
                           x = 2 * 65.00;
          writeFile.printf("%26s2 x 65.00 %10s $%.2f \n%55s \n%38s "
                           ,A[11],A[11],x,A[10],A[13]);
                           x = x + (x * Tax);
          writeFile.printf("\n%51s $%.2f \n\n%s",A[12],x,A[14]);                  
          writeFile.println();
       }
        System.out.println(" Your File receipts.txt has been successfully created");
        readFile.close();
        writeFile.close();
      }
    }

    So I tried to compile my coding it says something wrong with my WriteFile not being able to find a symbol and I don't understand what it means, I tried to check for what's wrong with it still can't find it..

    The coding is suppose to write a receipts for customers.. I am just doing a test run. haven't quite complete the whole thing yet. just want to know what's wrong with it.

    I attached the file that its suppose to read. just like I said it's just a test run. if it has something to do the file I'll finish it and ask for solutions for any problems..
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,198
    Thanks
    49
    Thanked 2,173 Times in 2,146 Posts

    Default Re: Cannot find symbol writefile

    it says something wrong
    please copy and paste here the full text of the error message so we can see what the problem is.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Cannot find symbol writefile

    Quote Originally Posted by Norm View Post
    please copy and paste here the full text of the error message so we can see what the problem is.
    Cannot Find Symbol - Variable writeFile

    And also I took a print screen just in case.
    Attached Images Attached Images

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,198
    Thanks
    49
    Thanked 2,173 Times in 2,146 Posts

    Default Re: Cannot find symbol writefile

    Cannot Find Symbol - Variable writeFile
    Where is the variable: writeFile defined? The compiler can not find its definition.

    What line is the error on? Can you copy and paste the full text of the compiler's error message?
    Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    17
    My Mood
    Depressed
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Cannot find symbol writefile

        while(readFile.hasNext())
        {
        ReceiptNo = readFile.nextDouble();
        PaymentTerm = readFile.next();
        CustomerName = readFile.next();
        ItemNo = readFile.next();
        ItemName = readFile.next();
        Quantity = readFile.nextDouble();
        Price = readFile.nextDouble();
     
     
        writeFile.printf("%53s \n%54s \n%53s \n%52s \n%52s \n%46s\n",A[0],A[1],A[2],A[3],A[4],A[5]);

    I'm sorry but I'm using BlueJ. the error is located at the writeFile.printf at the bottom as shown above.
    As you said where is the variable: writeFile defined

    what do you mean by it?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,198
    Thanks
    49
    Thanked 2,173 Times in 2,146 Posts

    Default Re: Cannot find symbol writefile

    what do you mean by it?
    All variables used in a program must be defined. Here are some sample definitions:
    int anIntVar;    //  define an int variable
    String aStringVar;  // Define a String variable
    Scanner aScannerVar;  // define a Scanner variable

    Where is the writeFile variable defined in your code?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    17
    My Mood
    Depressed
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Cannot find symbol writefile

     Scanner readFile = new Scanner(new FileReader("C:\\Users\\user\\Documents\\DIT MKJB\\Programming Java\\customer.txt"));
     
       PrintWriter writefile = new PrintWriter("C:\\Users\\user\\Desktop\\receipts.txt");
     
        while(readFile.hasNext())

    Ahh i see.. I did declare the writeFile. its shown above at the PrintWriter. it looks right to me surely i'm missing something.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,198
    Thanks
    49
    Thanked 2,173 Times in 2,146 Posts

    Default Re: Cannot find symbol writefile

    Try using the editor's Find tool with the Match Case option set and find writeFile in your code to see what is found.
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    Evilreaper (December 14th, 2012)

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

    Default Re: Cannot find symbol writefile

    Oh thank you so much I found the problem it was a careless mistake of lowercase and uppercase sensitivity.

  11. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,198
    Thanks
    49
    Thanked 2,173 Times in 2,146 Posts

    Default Re: Cannot find symbol writefile

    Java is very fussy about that.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Cannot Find Symbol
    By ChicoTheMan94 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 25th, 2012, 02:46 PM
  2. cannot find symbol
    By lanpan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 1st, 2012, 07:13 AM
  3. Cannot find symbol
    By waarten in forum What's Wrong With My Code?
    Replies: 18
    Last Post: January 11th, 2012, 02:15 PM
  4. Cannot find Symbol?
    By defmetalhead in forum What's Wrong With My Code?
    Replies: 8
    Last Post: July 5th, 2011, 08:48 AM
  5. Cannot find symbol?
    By stealthmonkey in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 10th, 2010, 09:02 PM

Tags for this Thread