Thanks so much. Here is the code for the 3 files:
import java.text.DecimalFormat;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
// Sort array alphabetically and get total value of inventory
public class Inventory
{ //begin class inventory
//formats output to currency format
public static DecimalFormat formatter = new DecimalFormat("$##,###.00");
public static void main(String[] args)
{ //begin main method
DVD productarray[] = new DVD [9]; //array declaration
productarray[0] = new DVD (1001, "Rocky", 5, 21.99, "1976");
//set first array
productarray[1] = new DVD (1002, "Rocky II", 7, 18.95, "1978");
//set second array
productarray[2] = new DVD (1003, "Rocky III", 12, 11.95, "1983");
//set third array
productarray[3] = new DVD (1004, "Rocky IV", 25, 12.95, "1985");
//set fourth array
productarray[4] = new DVD (1005, "Rocky V", 30, 9.95,
"1990");
productarray[5] = new DVD (1006, "Rocky Balboa", 19, 17.95,
"2006");
productarray[6] = new DVD (1007, "Arnold", 23, 5.25,
"1974");
productarray[7] = new DVD (1008, "Honey I Shrunk the Kids", 5, 17.95, "1989");
productarray[8] = new DVD (1009, "Gone With the Wind", 10, 25.75, "1939");
//set fifth array
productarray[productarray.length -1].arraysort(productarray);
//call sort method
JTextArea textArea1 = new JTextArea();
textArea1.append("Welcome to Inventory Program Part 5\n" +
"Melody's DVD Collection\n");
//greeting
for(int i =0; i < productarray.length; i++)
{ //begin for loop
textArea1.append("\nItem Number: " +
productarray[i].getItemNumber()
+"\n" +
"DVD Title: " + productarray[i].getProductName()+ "\n" +
"Number in Stock: " + productarray[i].getInStock()+ "\n"
+ "Price per DVD $: " + productarray[i].getItemPrice()
+ "\n" + "Value of Inventory for this DVD: " +
productarray[i].CalculateValuePrice() + "\n" +
"Year of movie: " + productarray[i].getYear() +
"\n" + "Restocking fee: " +
productarray[i].getRestockFee() + "\n");
//set display parameters
} //end for loop
textArea1.append("\nTotal Inventory Value: " +
productarray[productarray.length -1].CalculateTotalValue(productarray));
//display inventory total value
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(textArea1));
frame.setSize(600,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} //end main method
} //end class inventory
import java.text.DecimalFormat;
/**
*
* @author M
*/
public abstract class Product
{ //begin product class
//formats output to currency format
static DecimalFormat formatter = new DecimalFormat("$##,###.00");
private long ItemNumber; //declare item number
private String ProductName; //declare product name
private int InStock; //declare number in stock
private double ItemPrice; //declare price of each
private double ValuePrice; //declare value price
private static double TotalValue; //declare total value
public Product (long ItemNumber, String ProductName,
int InStock, double ItemPrice)//constructor
{ //begin constructor and set constructor values
this.ItemNumber = ItemNumber;
this.ProductName = ProductName;
this.InStock = InStock;
this.ItemPrice = ItemPrice;
} //end constructor
public double CalculateTotalValue (Product productarray[])
{//begin method
for (int i = 0; i < productarray.length; i++)
{//begin for loop
TotalValue = TotalValue + productarray[i].getValuePrice();
//statment to add value price through array
}//end for loop
return TotalValue;
}//end method
public abstract double CalculateValuePrice ();
public double getValuePrice ()
{//begin method
return ValuePrice;
}//end method
public long getItemNumber () //method to get item number
{ //begin method
return ItemNumber;
} //end method
public String getProductName () //method to get product name
{ //begin method
return ProductName;
} //end method
public int getInStock () //method to get products in stock
{ //begin method
return InStock;
} //end method
public double ItemValue() // Method to calculate the value of the inventory
{
return (double) ItemPrice * InStock;
}
public double getItemPrice () //method to get item price
{ //begin method
return ItemPrice;
} //end method
public void setValuePrice(double ValuePrice)
{ //begin method
this.ValuePrice = ValuePrice;
} //end method
public void arraysort(Product productarray[])
{ //begin method
for(int i = 0; i < productarray.length - 1; i++)
{//begin for loop
for(int c = i + 1; c < productarray.length; c++)
{ //begin for loop
String name1 = productarray[i].ProductName;
String name2 = productarray[c].ProductName;
if(name1.compareToIgnoreCase(name2) > 0)
{ //begin if statement
Product temp = productarray[i];
productarray[i] = productarray[c];
productarray[c] = temp;
}//end if statement
}//end for loop
}//end for loop
} //end method
} //end product class
import java.text.DecimalFormat;
/**
*
* @author M
*/
public class DVD extends Product
{//begin subclass
DecimalFormat format = new DecimalFormat("$##,###.00");
private String Year; //set variable for type of movie
private double RestockFee; //set variable for restocking fee
public DVD (long ItemNumber, String ProductName,
int InStock, double ItemPrice,String Year)
{ //begin constructor
super(ItemNumber, ProductName, InStock, ItemPrice);
this.Year = Year;
} //end constructor
public String getYear()
{//begin method
return Year;
}//end method
public double getRestockFee()
{//begin method
return RestockFee;
}//end method
@ Override
public double CalculateValuePrice()
{//begin method
double tempValue = getInStock() * getItemPrice();
RestockFee = tempValue *.05; //multiplication of 5% to value
setValuePrice (tempValue + RestockFee);//additon
return getValuePrice();
}//end method
@Override
public String toString()
{
return "\nThe year of the movie is: " + Year;
}
}//end subclass

New Topic/Question
Reply




MultiQuote




|