I knew I was forgetting something.
Thank you for the replies though. And before you even look, I know it doesn't look "pretty" yet. More concerned about functionality then looks at this point. Anyway, here is the rest of my code. And thanks again! After this I will tackle making it look more pleasing to the eye.
import java.util.Arrays;
public class Inventory4 {
public static void main(String[] args) {
FeatDVD dvd = null;
Inventory inventory = new Inventory();
dvd = new FeatDVD(0, "Superman", 5, 12.99f, "Action");
inventory.add(dvd);
dvd = new FeatDVD(1, "Resident Evil", 7, 14.99f, "Horror");
inventory.add(dvd);
dvd = new FeatDVD(2, "Hostel", 1, 10.00f, "Horror");
inventory.add(dvd);
dvd = new FeatDVD(3, "Office Space", 3, 15.99f, "Comedy");
inventory.add(dvd);
dvd = new FeatDVD(4, "Rambo", 8, 11.99f, "Action");
inventory.add(dvd);
dvd = new FeatDVD(5, "Spiderman", 2, 12.99f, "Action");
inventory.add(dvd);
dvd = new FeatDVD(6, "Star Trek", 7, 15.99f, "Drama");
inventory.add(dvd);
dvd = new FeatDVD(7, "Bruce Almighty", 10, 11.99f, "Comedy");
inventory.add(dvd);
inventory.display();
GUI gui = new GUI(inventory); // Start the GUI
} // end main
} // end class Inventory4
/**** Class decribes DVD while demostrating polymorphism and inheritance**/
class DVD implements Comparable
{
private int dvditem;
private String dvdtitle;
private int dvdstock;
private double dvdprice;
// Constructor
DVD()
{
dvditem = 0;
dvdtitle = "";
dvdstock = 0;
dvdprice = 0;
}// end constructor
//constructor initializes variables
DVD(int item, String title, int stock, double price)
{
this.dvditem = item;
this.dvdtitle = title;
this.dvdstock = stock;
this.dvdprice = price;
}
private void setTitle(String title)
{
this.dvdtitle = title;
}
public String getdvdTitle()
{
return dvdtitle;
}
private void setdvdItem(int item)
{
this.dvditem = item;
}
public int getdvdItem()
{
return dvditem;
}
private void setdvdStock(int stock)
{
this.dvdstock = stock;
}
public int getdvdStock()
{
return dvdstock;
}
private void setdvdPrice (double price)
{
this.dvdprice = price;
}
public double getdvdPrice()
{
return dvdprice;
}
public double getValue()
{
double value = dvdstock * dvdprice;
return value;
}
// This method tells the sort method what is to be sorted
public int compareTo(Object o)
{
return dvdtitle.compareTo(((DVD) o).getdvdTitle());
}
// This method passes the format for the string
public String toString()
{
return String.format("Unit number:%2d %-15s Units:%2d Price: $%5.2f Movie value: $%6.2f",
dvditem, dvdtitle, dvdstock, dvdprice, getValue());
}
} // end class DVD
/**** This is a subclass that adds 5% restocking fee and new feature***/
class FeatDVD extends DVD
{
private String genres;
// class constructor
FeatDVD(int item, String title, int stock, float price, String genres)
{
super(item, title, stock, price);
this.genres = genres;
}
public double getValue()
{ // getvalue method overrides
// getvalue method in the superclass
double value = 1.05F * super.getValue();
return value;
} // end getValue method
public String toString()
{ // toString method overrides the superclass toString method
// adding another fields
return super.toString() + " Genre:" + genres;
} // end toString method
} // end class FeatDVD
/*****class has inventory of DVDs.
* This class has methods to add and display dvds****/
class Inventory
{
private DVD[] dvds;
private int nCount;
// constructor
Inventory()
{
dvds = new DVD[10];
nCount = 0;
}
public void add(DVD dvd)
{
dvds[nCount] = dvd;
++nCount;
sort();
}
public int getNcount()
{
return nCount;
}
// method calculates total value of inventory
public double getTotalValue()
{
double totalValue = 0;
for (int i = 0; i < nCount; i++)
totalValue += dvds[i].getValue();
return totalValue;
} // end getTotalValue
public DVD getDVD(int n) //use in GUI
{ // protects n and keep in range
if (n <0 )
n = 0;
else if (n >= nCount)
n = nCount - 1;
return dvds[n];
}
// sorts the DVDs
private void sort()
{
Arrays.sort(dvds, 0, nCount);
}// end sort method
public void display()
{
System.out.println("\nThe inventory contains " + nCount + "DVDs\n");
for (int i = 0; i < nCount; i++)
System.out.printf("%d: %s\n", i, dvds[i]);
System.out.printf("\nTotal value of the inventory is $%.2f\n\n",
getTotalValue());
} // end display method
} // end class Inventory