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