Hello,
Thank you so much for the feedback, it's good to know that my subclass is ok. What I'm having problems with is creating object of class Book2 and calling the getBookAuthor().
When I attempt to compile my main file, I get the following 7 errors:
C:\java>javac Inventory_Program3.java
Inventory_Program3.java:48: cannot find symbol
symbol : constructor Book(java.lang.String,int,int,double,java.lang.Str ing)
location: class Book
myBook[0] = new Book("The Key Triology", 1, 25, 7.99, "Nora Robe
rts");
^
Inventory_Program3.java:49: cannot find symbol
symbol : constructor Book(java.lang.String,int,int,double,java.lang.Str ing)
location: class Book
myBook[1] = new Book("The Shinning", 2, 15, 5.99, "Steven King")
;
^
Inventory_Program3.java:50: cannot find symbol
symbol : constructor Book(java.lang.String,int,int,double,java.lang.Str ing)
location: class Book
myBook[2] = new Book("Wild Acre", 3, 7, 4.99, "Phillipa Gregory"
);
^
Inventory_Program3.java:51: cannot find symbol
symbol : constructor Book(java.lang.String,int,int,double,java.lang.Str ing)
location: class Book
myBook[3] = new Book("Dark Paradise", 4, 2, 12.99, "Tami Hoag");
^
Inventory_Program3.java:52: cannot find symbol
symbol : constructor Book(java.lang.String,int,int,double,java.lang.Str ing)
location: class Book
myBook[4] = new Book("Dollhouse Murders", 5, 18, 2.95, "Betty Re
n Wright");
^
Inventory_Program3.java:56: cannot find symbol
symbol : constructor Book2()
location: class Book2
Book2 author = new Book2();
^
Inventory_Program3.java:80: cannot find symbol
symbol : method getBookAuthor()
location: class Book
System.out.println("The book author is: " + myBook[i].ge
tBookAuthor());
^
7 errors
Here is some of my code from my main class:
- public class Inventory_Program3
-
{
-
-
// Declare an array of classes
-
private Book myBook[];
-
-
// method to sort inventory by book title
-
public Book[] sortBookInventory()
-
{
-
for(int i = 0; i < myBook.length; i++)
-
{
-
String bookTitle1 = myBook[i].getBookTitle();
-
int min = i;
-
String bookTitle = bookTitle1;
-
for(int j = i+1; j < myBook.length; j++)
-
{
-
String bookTitle2 = myBook[j].getBookTitle();
-
if(bookTitle2.compareTo(bookTitle) < 0)
-
{
-
min = j;
-
bookTitle = bookTitle2;
-
}
-
}
-
if(!bookTitle.equals(bookTitle1))
-
{
-
Book temp = myBook[i];
-
myBook[i] = myBook[min];
-
myBook[min] = temp;
-
}
-
}
-
return myBook;
-
} // end method sortBookInventory
-
-
// constructor
-
Inventory_Program3()
-
{
-
-
double totalInventoryValue = 0.0;
-
-
-
// Specify how many items are in the array
-
myBook = new Book[5];
-
myBook[0] = new Book("The Key Triology", 1, 25, 7.99, "Nora Roberts");
-
myBook[1] = new Book("The Shinning", 2, 15, 5.99, "Steven King");
-
myBook[2] = new Book("Wild Acre", 3, 7, 4.99, "Phillipa Gregory");
-
myBook[3] = new Book("Dark Paradise", 4, 2, 12.99, "Tami Hoag");
-
myBook[4] = new Book("Dollhouse Murders", 5, 18, 2.95, "Betty Ren Wright");
-
-
-
// instantiate Book2 object
-
Book2 author = new Book2();
-
-
// call method sort book inventory for display
-
sortBookInventory();
-
-
for (int i = 0; i<5; i++)
-
{
-
-
// display the book title
-
System.out.println("The book title is: " + myBook[i].getBookTitle());
-
-
// display the item number
-
System.out.println("The item number is: " + myBook[i].getItemNumber());
-
-
// display the number of units in stock
-
System.out.println("The number of units in stock is: " + myBook[i].getBookUnits());
-
-
// display the price per book
-
System.out.printf("The price of the book is: $%.2f\n", myBook[i].getBookPrice());
-
-
// display the value of the inventory
-
System.out.printf("The value of the inventory is: $%.2f\n", myBook[i].inventoryValue());
-
-
// display the book author
-
System.out.println("The book author is: " + myBook[i].getBookAuthor());