Here's my code, I cannot figure out what I am doing wrong. It is still displaying the output from the DVD class.
Code
public class Inventory_Program {
public static void main (String args [])
{//Start main method
//Instantiate DVD array
final int ARRAY_LENGTH = 5;//Constant to set array size
DVD dvd[] = new DVD[ARRAY_LENGTH];//Create an array of Person objects
DVD dvd1 = new DVD (01, " The Machinist", 25, 12.99, "Brad Anderson");//Creates an instance of the DVD class and initialize class instance variables
DVD dvd2 = new DVD (02, " X-Men:Last Stand", 16, 19.00, "Brett Ratner");//Creates an instance of the DVD class and initialize class instance variables
DVD dvd3 = new DVD (03, " The Dark Knight", 52, 19.99, "Christopher Nolan");//Creates an instance of the DVD class and initialize class instance variables
DVD dvd4 = new DVD (04, " Forrest Gump", 9, 9.99, "Robert Zemeckis");//Creates an instance of the DVD class and initialize class instance variables
DVD dvd5 = new DVD (05, " A Walk To Remember", 12, 5.00, "Adam Shankman");//Creates an instance of the DVD class and initialize class instance variables
dvd[0] = dvd1;//Add The Machinist DVD to the array of DVDs
dvd[1] = dvd2;//Add X-Men:Last Stand DVD to the array of DVDs
dvd[2] = dvd3;//Add The Dark Knight DVD to the array of DVDs
dvd[3] = dvd4;//Add Forest Gump DVD to the array of DVDs
dvd[4] = dvd5;//Add A Walk To Remember DVD to the array of DVDs
DVD.sort_by_name(dvd);//Call the sort_by_name method
System.out.println();
for (int n = 0; n < dvd.length; n++)
{
dvd[n].display_inventory_information();//display output to the console
System.out.println();
}
//Output the total value of the inventory
double total = 0.0;
for (int i = 0; i < 5; i++)
{
total += dvd[i].get_inventory_value();//A running total of get_inventory_value
}
System.out.printf("Total Value of Inventory is: \t$%.2f\n", total);//Outputs the total value of the inventory
}//End output
}//End method
Code
public class DVD
{
//Instance variable declarations
private int item_number; //Item number of product
private String product_name; //Product name
private int units_in_stock; //Number of units in stock
private double price_per_unit; //Price per unit
public DVD (){}
//DVD constructor
public DVD (int item, String name, int stock, double price, String director) {
item_number = item;
product_name = name;
units_in_stock = stock;
price_per_unit = price;
}//End constructor
public void set_item_number (int item)
{//Start Method
this.item_number = item;//Set variable to be passed with the method
} //End method
public int get_item_number()
{//Start Method
return item_number;//Get the value of the instance variable
}//End method
public void set_product_name (String name)
{//Start Method
this.product_name = name;//Set variable to be passed with the method
}//End method
public String get_product_name()
{//Start Method
return product_name;//Get the value of the instance variable
}//End method
public void set_units_in_stock (int stock)
{//Start Method
this.units_in_stock = stock;//Set variable to be passed with the method
}//End method
public double get_units_in_stock()
{//Start Method
return units_in_stock;//Get the value of the instance variable
}//End method
public void set_price_per_unit (double price)
{//Start Method
this.price_per_unit = price;//Set variable to be passed with the method
}//End method
public double get_price_per_unit()
{//Start Method
return price_per_unit;//Get the value of the instance variable
}//End method
//calculate inventory value
public double get_inventory_value()
{//Start Method
return units_in_stock * price_per_unit;//Get the value of the instance variable
}//End method
public double get_inventory_total_value()
{//Start Method
double value = 0;
for(int i = 0; i < 5; i++)
{
value = get_inventory_value();
}
return value;
}//End method
public void display_inventory_information()
{//Displays DVD information to the console
System.out.println("Product Number: \t\t" + this.get_item_number());
System.out.println("Product Name: \t\t\t" + this.get_product_name());
System.out.println("Number of Units in Stock: \t" + this.get_units_in_stock());
System.out.printf("Price per Unit: \t\t$%.2f\n", + this.get_price_per_unit());
System.out.printf("Value of Inventory: \t\t$%.2f\n", + this.get_inventory_value());
System.out.println();
}//End method
public static void sort_by_name(DVD[] dvd)
{//Start Method
DVD temp;
for(int j = dvd.length -2;j>=0;j--)
for(int n=0;n<=j;n++)
if(dvd[n].get_product_name().compareTo(dvd[n+1].get_product_name())>0)
{
temp=dvd[n];
dvd[n]=dvd[n+1];
dvd[n+1]=temp;
}
}//End method
}//End class
Code
class Director extends DVD
{//being Director class
//Instance variable declaration
protected String director;
public Director (){}
//Director constructor
Director(int item_number, String product_name, int units_in_stock, double price_per_unit, String dvd_director)
{//Start Method
super(item_number, product_name, units_in_stock, price_per_unit, dvd_director);
this.director = dvd_director;
}//End constructor
// set release date
public void set_director(String dvd_director)
{//Start Method
this.director = dvd_director;
}//End method
// return release date
public String get_director()
{//Start Method
return director;
}//End method
// add 5% restocking fee
public double get_restocking_fee()
{//Start Method
return get_price_per_unit() * .05;
}//End method
@Override
public void display_inventory_information()
{//Displays DVD information to the console
System.out.println("Product Number: \t\t" + this.get_item_number());
System.out.println("Product Name: \t\t\t" + this.get_product_name());
System.out.println("Product Director: \t\t" + String.valueOf(this.get_director()));
System.out.println("Number of Units in Stock: \t" + this.get_units_in_stock());
System.out.println("Restocking fee: \t\t$%.2f\n" + this.get_restocking_fee());
System.out.printf("Price per Unit: \t\t$%.2f\n", + this.get_price_per_unit());
System.out.printf("Value of Inventory: \t\t$%.2f\n", + this.get_inventory_value());
System.out.println();
}//End method
}//End class