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

Thread: getCurrencyInstance = Cannot find symbol

  1. #1
    Member
    Join Date
    Mar 2013
    Posts
    33
    My Mood
    Innocent
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default getCurrencyInstance = Cannot find symbol

    Hi. Please review my code. I'm trying to use println to print an RRP variable of $79.99 for book1. But I think it cannot recognize it because RRP is declared in the Main class (Book.java) whilst I am trying to use it from the driver class (Bookshelf.java). Can someone please advise me what to do?

    Main class:
     
    //Book.java
    //conatains instance data for title, author, publisher, and copyright date.
    //Has getter and setter and toString returns a multi line formatted 
    //description of each book.
     
    public class Book
    {
      private String copyrightDate;
      private String title;
      private String author;
      private String publisher;
      private double RRP;
     
     
      //constructor:
      public Book ()
      {
        copyrightDate = "11.04.1993";
        title = "A book about Bookish People"; 
        author = "Jim McMorrison";
        publisher = "Selwyn House";
        RRP = 79.99;
      }
     
      //getter
      public double getRRP ()
      {
        return RRP;
      }
     
      //setter
      public void setRRP (double value)
      {
        RRP = value;
      }
     
      //getter
      public String getCopyrightDate ()
      {
        return copyrightDate;
      }
     
      //setter
      public void setCopyrightDate (String value)
      {
        copyrightDate = value;
      }
     
      //getter
      public String getTitle ()
      {
        return title;
      }
     
      //setter
      public void setTitle (String value)
      {
        title = value;
      }
     
     
      //getter
      public String getAuthor ()
      {
        return author;
      }
     
     
      //setter
      public void setAuthor (String value)
      {
        author = value;
      }
     
     
      //getter
      public String getPublisher ()
      {
        return publisher;
      }
     
     
      //setter
      public void setPublisher (String value)
      {
        publisher = value;
      }
     
    }

    Driver class:
     
    //Bookshelf.java
    //a driver class to instantiate and update several Book objects.
     
    import java.text.NumberFormat;
     
    public class Bookshelf
    {
      public static void main (String[] args)
      {
      Book Book1, Book2;
     
      Book1 = new Book ();
     
      NumberFormat fmt1 = NumberFormat.getCurrencyInstance();
     
      Book1.setAuthor ("Balls McClary");
      Book1.setCopyrightDate ("8.04.2007");
     
      System.out.println ();
      System.out.println ("\tTitle is: " + Book1.getTitle());
      System.out.println ("\tAuthor: " + Book1.getAuthor ());
      System.out.println ("\tDate of publication: " + 
                         Book1.getCopyrightDate());
      System.out.println ("\tPublishers House: " + Book1.getPublisher());
      System.out.println ("The recommended retail price is: " + 
                         fmt1.format(RRP));  
     
      System.out.println ();
     
     }
    }

    And the error:
    craig@craig-laptop:~/Documents/panda/MyPrograms$ javac Bookshelf.java
    Bookshelf.java:26: error: cannot find symbol
                         fmt1.format(RRP));  
                                     ^
      symbol:   variable RRP
      location: class Bookshelf
    1 error


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: getCurrencyInstance = Cannot find symbol

    But I think it cannot recognize it because RRP is declared in the Main class (Book.java) whilst I am trying to use it from the driver class (Bookshelf.java).
    Yes, you're right.

    What you should do is not use RRP but, instead, use a getter method for the price as you do for Book1.getTitle(), Book1.getPublisher() etc.

    ---

    Java coding conventions say that methods and variables should start with a lowercase letter: so book1 with a small b. RRP is a funny case - you could use rRP although I think I would call it price or rrPrice.

  3. The Following User Says Thank You to pbrockway2 For This Useful Post:

    craigjlner (May 12th, 2013)

  4. #3
    Member
    Join Date
    Mar 2013
    Posts
    33
    My Mood
    Innocent
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: getCurrencyInstance = Cannot find symbol

    Thanks for your help, that worked a charm

  5. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: getCurrencyInstance = Cannot find symbol

    You're welcome.

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 waarten in forum What's Wrong With My Code?
    Replies: 18
    Last Post: January 11th, 2012, 03:15 PM
  3. Cannot find symbol
    By BadgerWatch in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 6th, 2011, 11:25 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, 10:02 PM