Java: using arrays with objects, can't find symbol

Genkora

Frog blast the vent core!
Reaction score
92
Never mind, I fixed it and it works. Sorry for the pointless thread

I'm writing a program that allows a user to put in some data on a book, and get it back in a nice organized manner. It is an assignment for my class, but I'm using a loop to allow the user to put in as many books as they want, which also requires I use an array. The assignment doesn't call for a loop or arrays, but I feel icky writing a program that demands the user put in data for an exact amount of books.

I can do what the assignment calls for just fine, but when I try to compile my souped up code it cannot find the symbol for my object, which is confusing the hell out of me as I clearly declared it.

Here is my driver class

Code:
import java.util.Scanner;

public class Bookshelf
{
	public static void main (String[] args)
	{
		String titl, auth, pub;
		int copy, num, index1 = 1, choice = 1;
		Scanner scan = new Scanner(System.in);
		do
		{
			System.out.print("\nTitle: ");
			titl = scan.nextLine();
			System.out.print("\nAuthor: ");
			auth = scan.nextLine();
			System.out.print("\nPublisher: ");
			pub = scan.nextLine();
			System.out.print("\nCopyright date: ");
			copy = scan.nextInt();

			//creates a new book every time the loop is run

			Book[] book = new Book[index1];
			book[index1] = new Book(titl,auth,pub,copy);
			index1 = index1 + 1;
			System.out.println("Would you like to enter another book? Hit 1 for yes or 0 for no and hit enter");
			choice = scan.nextInt();
		}
		while (choice != 0);
		
		num = index1;
		index1 = 1;
		
		do //prints out all the data on every book entered.  Well, it should
		{
			[B]System.out.println(book[index1].toString());[/B]
			index1 = index1 +1;
		}
		while (index1 <= num);
	}
}

The error is in the bolded line, it says it cannot find the symbol for book. I'm still in the experimental stages of using arrays, but I feel like I understand them fairly well. The problem is most likely some stupid thing I'm just not doing, but I'd really appreciate any help.

I'm certain the problem isn't in my object, but here it is anyway.

Code:
public class Book
{
	private String title, author, publisher;
	private int copyright;

	Book(String titl, String auth, String pub, int copy)
	{
		title = titl;
		author = auth;
		publisher = pub;
		copyright = copy;
	}
	public String getTitle()
	{
		return title;
	}
	public String getAuthor()
	{
		return author;
	}
	public String getPublisher()
	{
		return publisher;
	}
	public int getCopyright()
	{
		return copyright;
	}
	public void setTitle(String titl)
	{
		title = titl;
	}
	public void setAuthor(String auth)
	{
		author = auth;
	}
	public void setPublisher(String pub)
	{
		publisher = pub;
	}
	public void setCopyright(int copy)
	{
		copyright = copy;
	}
	public String toString()
	{

		return "\nTitle: "+title+"\nAuthor: "+author+"\nPublisher: "+publisher+"\nCopyright: "+copyright+"\n~~~~~~~~~~~~~~";
	}
}
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top