3 Replies - 4795 Views - Last Post: 19 January 2009 - 01:40 PM Rate Topic: -----

#1 h2o pete  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-January 09

Cannot find symbol error

Posted 19 January 2009 - 01:26 PM

Bit stuck on this now lol.

The question I've been set is:

Add two accessor methods to the class - getAuthor and getTitle - that return the author and title fields as their respective results.
Test your class by creating some instances and calling the methods.


Every time I try to create a new book I get a cannot find symbol error.

e.g.

If I try to make a book with "john" as the author and "beingjohn" as the title I get this:

Error: cannot find symbol - variable john


It's probably something really stupid that I'm not seeing haha.

I haven't been doing this long at all so I'm still not too confident with programming.

I'm using BlueJ software by the way.

I've got this so far:

/**
 * A class that maintains information on a book.
 * This might form part of a larger application such
 * as a library system, for instance.
 *
 * @author (Peter Moncrieff.)
 * @version (17th January 2009.)
 */
class Book
{
	private String author;
	private String title;

	/**
	 * Set the author and title fields when this object
	 * is constructed.
	 */
	public Book(String bookAuthor, String bookTitle)
	{
		author = bookAuthor;
		title = bookTitle;
	}
	/**
	 * Accesses the author
	 */
	public String getbookAuthor()
	{
		return author;
	}
	
	/**
	 * Accesses the title
	 */
	public String getbookTitle()
	{
		return title;
	}
}





Thanks.

This post has been edited by h2o pete: 19 January 2009 - 01:27 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Cannot find symbol error

#2 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Cannot find symbol error

Posted 19 January 2009 - 01:32 PM

Are you calling the constructor like this?

Book book = new Book(john, beingJohn);

// or like this...?

Book book = new Book("John", "Being John");


The 2nd one is what you're looking for I believe. Strings are always enclosed in quotes, unless they are variables...like this next one.

String john = "John";
String beingJohn = "Being John";

Book book = new Book(john, beingJohn);


That one works equally well.
Was This Post Helpful? 1
  • +
  • -

#3 h2o pete  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 19-January 09

Re: Cannot find symbol error

Posted 19 January 2009 - 01:39 PM

View PostLocke37, on 19 Jan, 2009 - 12:32 PM, said:

Are you calling the constructor like this?

Book book = new Book(john, beingJohn);

// or like this...?

Book book = new Book("John", "Being John");


The 2nd one is what you're looking for I believe. Strings are always enclosed in quotes, unless they are variables...like this next one.

String john = "John";
String beingJohn = "Being John";

Book book = new Book(john, beingJohn);


That one works equally well.


Oh I know what I did wrong now!

*Slaps forehead*

I'm using BlueJ so all I have to do is right click then select new book. I have to type in the author name and book title. I forgot to put them in quotes haha..

Thanks for the help it's working now :).
Was This Post Helpful? 0
  • +
  • -

#4 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Cannot find symbol error

Posted 19 January 2009 - 01:40 PM

Glad I could help! :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1