to store the items. The output should display the information one product at a time,
including the item number, the name of the product, the number of units in stock, the
price of each unit, and the value of the inventory of that product. In addition, the output
should display the value of the entire inventory.
Create a method to calculate the value of the entire inventory.
Create another method to sort the array items by the name of the product.
I get alot of errors on the inventory2 class when I compile.
Inventory2 class
import java.util.Arrays;
public class Inventory2
{
public static void main(String[] args) {
System.out.println("\nCheckPoint - Inventory2");
System.out.println("Thomas' DVD Collection\n");
String dvd[];
dvd = new DVD[4];
DVD dvd = null;
dvd[0]= new DVD(1, "Spiderman", 40, 14.95);
System.out.println(dvd);
dvd[1]= new DVD(2, "Superman", 10, 14.95);
System.out.println(dvd);
dvd[2]= new DVD(3, "X-Men", 20, 14.95);
System.out.println(dvd);
dvd[3]= new DVD(4, "Fantastic Four", 50, 14.95);
System.out.println(dvd);
for (int i=0; i<4; i++) {
System.out.println("DVD " + i + " : " + DVD[i]);
}
Arrays.sort(DVD);
for (int i=0; i<4; i++) {
System.out.println("DVD " + i + " : " + DVD[i]);
}
System.out.println("\nProgram Done\n");
}
} // end class Inventory2
C:\IT315\Inventory2\Inventory2.java:17: incompatible types
found : DVD[]
required: java.lang.String[]
dvd = new DVD[4];
^
C:\IT315\Inventory2\Inventory2.java:19: dvd is already defined in main(java.lang.String[])
DVD dvd = null;
^
C:\IT315\Inventory2\Inventory2.java:21: incompatible types
found : DVD
required: java.lang.String
dvd[0]= new DVD(1, "Spiderman", 40, 14.95);
^
C:\IT315\Inventory2\Inventory2.java:24: incompatible types
found : DVD
required: java.lang.String
dvd[1]= new DVD(2, "Superman", 10, 14.95);
^
C:\IT315\Inventory2\Inventory2.java:27: incompatible types
found : DVD
required: java.lang.String
dvd[2]= new DVD(3, "X-Men", 20, 14.95);
^
C:\IT315\Inventory2\Inventory2.java:30: incompatible types
found : DVD
required: java.lang.String
dvd[3]= new DVD(4, "Fantastic Four", 50, 14.95);
^
C:\IT315\Inventory2\Inventory2.java:34: cannot find symbol
symbol : variable DVD
location: class Inventory2
System.out.println("DVD " + i + " : " + DVD[i]);
^
C:\IT315\Inventory2\Inventory2.java:37: cannot find symbol
symbol : variable DVD
location: class Inventory2
Arrays.sort(DVD);
^
C:\IT315\Inventory2\Inventory2.java:40: cannot find symbol
symbol : variable DVD
location: class Inventory2
System.out.println("DVD " + i + " : " + DVD[i]);
^
9 errors
Exit code: 1
There were errors
My DVD class compiles good...
DVD class
public class DVD {
private int ItemNo;
private String Title;
private int Quantity;
private double Price;
DVD(int itemNo, String title, int quantity, double price) {
ItemNo = itemNo;
Title = title;
Quantity = quantity;
Price = price;
} //end constructor
// set DVD name
public void setTitle(String title) {
Title = title;
} //end method setDvdTitle
//return DVD Title
public String getTitle() {
return Title;
} //end method getDvdTitle
//set DVD quantity
public void setQuantity(int quantity) {
Quantity = quantity;
} //end method setdvdQuantity
//return dvdQuantity
public double getQuantity() {
return Quantity;
} //end method get dvdQuantity
public void setPrice(double price) {
Price = price;
} //end method setDvdPrice
//return dvdPrice
public double getPrice() {
return Price;
} //end method get Dvd Price
public void setItemNo(int item) {
ItemNo = item;
} //end method setdvdItemNo
//return DVD item
public int getItemNo() {
return ItemNo;
} //end method getdvdItemNo
//calculate inventory value
public double value() {
return Price * Quantity;
} //end method value
public String toString() {
return String.format("Item#=%03d Title=%-15s Quantity=%3d Price=$%6.2f Value=$%7.2f",
ItemNo, Title, Quantity, Price, value());
}
} //end class DVD
This post has been edited by tjbedgood2: 03 October 2007 - 08:24 PM

New Topic/Question
Reply




MultiQuote



|