I know that there is already codes for numerous different inventory programs. I have read them, and I am still somewhat confused. OK, this is what my code is supposed to be doing: Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the DVDs subclass, you could use movie title, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method previously created for the product class. The subclass method should also add a 5% restocking fee to the value of the inventory of that product.
• Modify the output to display this additional feature you have chosen and the restocking fee.
This is the errors I keep getting: /tmp/27473/Product.java:10: class, interface, or enum expected
{
^
/tmp/27473/Product.java:13: class, interface, or enum expected
product[1] = new Product(2, "Clown Trigger", 1, 74.99);
^
/tmp/27473/Product.java:14: class, interface, or enum expected
product[2] = new Product(3, "Blueline Trigger", 2, 59.99);
^
/tmp/27473/Product.java:15: class, interface, or enum expected
product[3] = new Product(4, "Queen Trigger", 1, 99.99);
^
/tmp/27473/Product.java:18: class, interface, or enum expected
total = (inventory[ 0 ].getValueOfStock() +
^
/tmp/27473/Product.java:23: class, interface, or enum expected
System.out.printf( "The total value of the inventory is: $%.2f\n\n", total );
^
/tmp/27473/Product.java:26: class, interface, or enum expected
public Product(int number, String name, int quantity, double price) {
^
/tmp/27473/Product.java:28: class, interface, or enum expected
this.name = name;
^
/tmp/27473/Product.java:29: class, interface, or enum expected
this.quantity = quantity;
^
/tmp/27473/Product.java:30: class, interface, or enum expected
this.price = price;
^
/tmp/27473/Product.java:31: class, interface, or enum expected
}
^
/tmp/27473/Product.java:33: class, interface, or enum expected
public String getName() { return name; }
^
/tmp/27473/Product.java:33: class, interface, or enum expected
public String getName() { return name; }
^
/tmp/27473/Product.java:34: class, interface, or enum expected
public int getNumber() { return number; }
^
/tmp/27473/Product.java:34: class, interface, or enum expected
public int getNumber() { return number; }
^
/tmp/27473/Product.java:35: class, interface, or enum expected
public double getPrice() { return price; }
^
/tmp/27473/Product.java:35: class, interface, or enum expected
public double getPrice() { return price; }
^
/tmp/27473/Product.java:36: class, interface, or enum expected
public int getQuantity() { return quantity; }
^
/tmp/27473/Product.java:36: class, interface, or enum expected
public int getQuantity() { return quantity; }
^
/tmp/27473/Inventory.java:26: illegal start of expression
public void getInventory() {
^
20 errors
Finally, here is my codes:
CODE
public class Inventory
{
public static final int MAXIMUM_ITEMS = 4;
Product product[] = new Product[MAXIMUM_ITEMS];
public Inventory(){
buildInventory();
getInventory();
}
public void buildInventory() {
product[0] = new Fish(0, "Fancy Tailed Guppy", 25, 4.99);
product[1] = new Fish(1, "Huma Huma Picasso Trigger", 2, 35.99);
product[2] = new Fish(2, "Black Durgeon Trigger", 1, 99.99);
product[3] = new Fish(3, "Niger Trigger", 2, 45.99);
product[4] = new Fish(4, "Jack Dempsey Cichlid", 4, 19.99);
product[5] = new Fish(5, "Midas Cichlid", 1, 69.99);
product[6] = new Fish(6, "Neon Tetra", 25, 2.99);
product[7] = new Fish(7, "Convict Cichlid", 2, 15.99);
product[8] = new Fish(8, "Oscar", 4, 37.99);
product[9] = new Fish(9, "Albino Cory Cat", 1, 29.99);
public void getInventory() {
for(int i = 0; i < product.length; i++) {
System.out.println("Number: " + product.getNumber());
System.out.println("Name: " + product.getName());
System.out.println("Quantity: " + product.getQuantity());
System.out.println("Price: " + product.getPrice());
System.out.println("Item Value: " +
product.getQuantity() * product.getPrice());
System.out.printIn("Item Value:"+product.getQuantity() * product.getPrice() * 0.05);
System.out.println();
}
}
}
CODE
public class Product {
private String name = "";
private int number = 0;
private double price = 0;
private int quantity = 0;
}
{
product[0] = new Product(1, "Bursa Trigger", 3, 39.99);
product[1] = new Product(2, "Clown Trigger", 1, 74.99);
product[2] = new Product(3, "Blueline Trigger", 2, 59.99);
product[3] = new Product(4, "Queen Trigger", 1, 99.99);
total = (inventory[ 0 ].getValueOfStock() +
inventory[ 1 ].getValueOfStock() +
inventory[ 2 ].getValueOfStock() +
inventory[ 3 ].getValueOfStock() +
inventory[ 4 ].getValueOfStock());
System.out.printf( "The total value of the inventory is: $%.2f\n\n", total );
public Product(int number, String name, int quantity, double price) {
this.number = number;
this.name = name;
this.quantity = quantity;
this.price = price;
}
public String getName() { return name; }
public int getNumber() { return number; }
public double getPrice() { return price; }
public int getQuantity() { return quantity; }
}
CODE
public class Fish{
public Fish() {}
public static void main( String args[] ) {
new Inventory ();
}
}
I have been reading and rereading, but I just get more and more confused. When I think I do something right, I ask my teacher and he makes me feel like an idiot. Any help at all is greatly appreciated. Thanks!
Ok, I've been working on the code trying to get rid of some of the errors. I am down to one in my inventory.java file. This is the error: Inventory.java:26: illegal start of expression
public void getInventory() {
^
This is the errors for the other codes: /tmp/18746/Inventory.java:26: illegal start of expression
public void getInventory() {
^
/tmp/18746/Product.java:9: class, interface, or enum expected
product[0] = new Product(1, "Bursa Trigger", 3, 39.99);
^
/tmp/18746/Product.java:10: class, interface, or enum expected
product[1] = new Product(2, "Clown Trigger", 1, 74.99);
^
/tmp/18746/Product.java:11: class, interface, or enum expected
product[2] = new Product(3, "Blueline Trigger", 2, 59.99);
^
/tmp/18746/Product.java:12: class, interface, or enum expected
product[3] = new Product(4, "Queen Trigger", 1, 99.99);
^
/tmp/18746/Product.java:15: class, interface, or enum expected
(inventory[ 0 ].getValueOfStock() +
^
/tmp/18746/Product.java:20: class, interface, or enum expected
System.out.printf( "The total value of the inventory is: $%.2f\n\n", total );
^
/tmp/18746/Product.java:23: class, interface, or enum expected
public Product(int number, String name, int quantity, double price) {
^
/tmp/18746/Product.java:25: class, interface, or enum expected
this.name = name;
^
/tmp/18746/Product.java:26: class, interface, or enum expected
this.quantity = quantity;
^
/tmp/18746/Product.java:27: class, interface, or enum expected
this.price = price;
^
/tmp/18746/Product.java:28: class, interface, or enum expected
}
^
/tmp/18746/Product.java:30: class, interface, or enum expected
public String getName() { return name; }
^
/tmp/18746/Product.java:30: class, interface, or enum expected
public String getName() { return name; }
^
/tmp/18746/Product.java:31: class, interface, or enum expected
public int getNumber() { return number; }
^
/tmp/18746/Product.java:31: class, interface, or enum expected
public int getNumber() { return number; }
^
/tmp/18746/Product.java:32: class, interface, or enum expected
public double getPrice() { return price; }
^
/tmp/18746/Product.java:32: class, interface, or enum expected
public double getPrice() { return price; }
^
/tmp/18746/Product.java:33: class, interface, or enum expected
public int getQuantity() { return quantity; }
^
/tmp/18746/Product.java:33: class, interface, or enum expected
public int getQuantity() { return quantity; }
^
20 errors
Doesn't look like I've made much difference!
Here is the code once again:
CODE
public class Inventory
{
public static final int MAXIMUM_ITEMS = 4;
Product product[] = new Fish[MAXIMUM_ITEMS];
public Inventory(){
buildInventory();
getInventory();
}
public void buildInventory() {
product[0] = new Fish(0, "Fancy Tailed Guppy", 25, 4.99);
product[1] = new Fish(1, "Huma Huma Picasso Trigger", 2, 35.99);
product[2] = new Fish(2, "Black Durgeon Trigger", 1, 99.99);
product[3] = new Fish(3, "Niger Trigger", 2, 45.99);
product[4] = new Fish(4, "Jack Dempsey Cichlid", 4, 19.99);
product[5] = new Fish(5, "Midas Cichlid", 1, 69.99);
product[6] = new Fish(6, "Neon Tetra", 25, 2.99);
product[7] = new Fish(7, "Convict Cichlid", 2, 15.99);
product[8] = new Fish(8, "Oscar", 4, 37.99);
product[9] = new Fish(9, "Albino Cory Cat", 1, 29.99);
public void getInventory() {
for(int i = 0; i < product.length; i++) {
System.out.println("Number: " + Fish.getNumber());
System.out.println("Name: " + Fish.getName());
System.out.println("Quantity: " + Fish.getQuantity());
System.out.println("Price: " + Fish.getPrice());
System.out.println("Item Value: " +
Fish.getQuantity() * Fish.getPrice());
System.out.printIn("Item Value:"+product.getQuantity() * product.getPrice() * 0.05);
System.out.println();
}
}
}
public class Product {
private String name = "";
private int number = 0;
private double price = 0;
private int quantity = 0;
}
product[0] = new Product(1, "Bursa Trigger", 3, 39.99);
product[1] = new Product(2, "Clown Trigger", 1, 74.99);
product[2] = new Product(3, "Blueline Trigger", 2, 59.99);
product[3] = new Product(4, "Queen Trigger", 1, 99.99);
(inventory[ 0 ].getValueOfStock() +
inventory[ 1 ].getValueOfStock() +
inventory[ 2 ].getValueOfStock() +
inventory[ 3 ].getValueOfStock() +
inventory[ 4 ].getValueOfStock());
System.out.printf( "The total value of the inventory is: $%.2f\n\n", total );
public Product(int number, String name, int quantity, double price) {
this.number = number;
this.name = name;
this.quantity = quantity;
this.price = price;
}
public String getName() { return name; }
public int getNumber() { return number; }
public double getPrice() { return price; }
public int getQuantity() { return quantity; }
}
public class Fish{
public Fish() {}
public static void main( String args[] ) {
new Inventory ();
}
}
Again, thanks for any help!
This post has been edited by mudpuppy: 13 Aug, 2007 - 09:05 PM