Solved: java programming help
What I need to do is create a toString to show the genre of the DVDs, and also show a 5% restocking fee...Code below
import java.util.Arrays;
public class Inventory3 {
public static void main(String[] args) {
TypedDVD dvd = null;
Inventory inventory = new Inventory(); // Create a new inventory
System.out.println("\nNorman's DVD Inventory\n");
dvd = new TypedDVD(0, "Mother,Jugs and Speed", 1, 15.00f, "Comedy");
inventory.add(dvd);
dvd = new TypedDVD(1, "Clash of the Titans", 10, 12.49f, "Fiction");
inventory.add(dvd);
dvd = new TypedDVD(2, "300", 1, 1.00f, "History");
inventory.add(dvd);
dvd = new TypedDVD(3, "Full Metal Jacket", 2, 20.00f, "War");
inventory.add(dvd);
dvd = new TypedDVD(4, "Jarhead", 5, 5.00f, "War");
inventory.add(dvd);
inventory.display();
System.out.println("That's all, folks!\n");
} // end main method
} // end class Inventory3
class DVD {
private int productNumber;
private String title;
private int numCopies;
private float price;
DVD(int productNumber, String title, int numCopies, float price) {
this.productNumber = productNumber;
this.title = title;
this.numCopies = numCopies;
this.price = price;
}
public String toString() {
return String.format("ProdNum= %3d Title= %-25s numCopies= %3d price= $%6.2f value= $%7.2f",
productNumber, title, numCopies, price, value());
}
public float value() {
return numCopies * price;
}
} // end class DVD
class TypedDVD extends DVD {
private String genre;
TypedDVD(int productNumber, String title, int numCopies, float price, String genre) {
super(productNumber, title, numCopies, price);
this.genre = genre;
public String toString() {
return String.format("ProdNum= %3d Title= %-25s numCopies= %3d price= $%6.2f genre= %-25s value= $%7.2f",
productNumber, title, numCopies, price, genre, value());
}
public float restockingFee() {
return super.value() * 0.05f;
System.out.printf("\nThe restocking fee is $%.2f\n\n", value());
}
public float value() {
return super.value() + restockingFee();
}
} // end TypedDVD class
class Inventory {
private DVD[] dvds;
private int numDVDs;
Inventory() {
dvds = new DVD[10];
numDVDs = 0;
}
// Add a DVD to the collection
public void add(DVD dvd) {
dvds[numDVDs] = dvd;
++numDVDs;
}
public float value() {
float total = 0;
for (int i = 0; i < numDVDs; i++)
total += dvds[i].value();
return total;
}
public void display() {
System.out.println("There are " + numDVDs + " DVDs in the collection\n");
for (int i = 0; i < numDVDs; i++)
System.out.println(dvds[i]);
System.out.printf("\nTotal value of the collection is $%.2f\n\n", value());
}
} //end class Inventory