Please help, my inventory code is not working
I have been struggling with this program. It's an inventory program for class. It won't run and I need to modify it today with the following criteria Please help:
Use an array 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.
My Code:
Code Java:
package inventory1;
/**
*
* @author Gary
*/
public class Inventory1 {
public static void main(String args []) {
class dvd {
public dvd(int i, String Matrix, int i0, double dvd) {
}
}
DVD dvd;
Object DVD dvd = new DVD (1, "Matrix", 5, 2.15);
System.out.println(dvd);
DVD dvd1 = new DVD (2,"Aliens", 7, 1.23);
System.out.println(dvd);
DVD = new dvd (3, "Twilight", 6, 3.65);
System.out.println(dvd);
DVD = new dvd (4, "Hurt Locker", 3, 2.10);
System.out.println(dvd);
System.out.println("Product Title is " + dvd.getDvdTitle());
System.out.println("The number of units in stock is" + dvd.getDvdStock());
System.out.println("The price of each DVD is" + dvd.getDvdPrice());
System.out.println("The item number is " + dvd.getDvdItem());
System.out.println("The value of the inventory is" + dvd.value());
} //end main
} // end class Inventory1
class DVD {
private String dvdTitle;
private double dvdStock;
private double dvdPrice;
private double dvdItem;
public DVD(String title, double stock, double price, double item) {
dvdTitle = title;
dvdStock = stock;
dvdPrice = price;
dvdItem = item;
} //end four-argument constructor
// set DVD name
public void setDvdTitle(String title) {
dvdTitle = title;
} //end method setDvdTitle
//return DVD Title
public String getDvdTitle() {
return dvdTitle;
} //end method getDvdTitle
//set DVD Stock
public void setDvdStock(double stock) {
dvdStock = stock;
} //end method setDvdStock
//return DvdStock
public double getDvdStock() {
return dvdStock;
} //end method get Dvdstock
public void setDvdPrice(double price) {
dvdPrice = price;
} //end method setDvdPrice
//return dvdPrice
public double getDvdPrice() {
return dvdPrice;
} //end method get Dvd Price
public void setDvdItem(double item) {
dvdItem = item;
} //end method setdvdItem
//return DVD item
public double getDvdItem() {
return dvdItem;
} //end method getDvdItem
//calculate inventory value
public double value() {
return dvdPrice * dvdStock;
} //end method value
} //end class DVD
Re: Please help, my inventory code is not working
Please explain. If you are getting errors, copy the full text of the messages and paste them here.
Re: Please help, my inventory code is not working
At line 26 it gives the following error:
';' expected
required string, double, double, double
Re: Please help, my inventory code is not working
Which line is line 26?
What is "required string, double, double, double"?
It'd be better if you posted the full text of the error message and not just copy a few lines.
Please copy full text of error message and paste it here. Here is a sample:
Code :
TestSorts.java:138: cannot find symbol
symbol : variable var
location: class TestSorts
var = 2;
^
Re: Please help, my inventory code is not working
Line 26:
[highlight=Java]
Object DVD dvd = new DVD (1, "Matrix", 5, 2.15);
[/hightlight]
Re: Please help, my inventory code is not working
There are two data types at the start of the line: Object and DVD
There should only be one. What data type do you want to define the variable: dvd to be?
Remove the other data type.
See this line:
The code looks like you tried many different ways to code it. Most of them are wrong.
I suggest that you delete all of them and work on just one. Code it and then compile it.
If there are errors, fix the errors and compile it again.
Don't type in any more statements until all the errors are fixed.
Work on ONE PROBLEM AT A TIME.
Re: Please help, my inventory code is not working
Dude I have no idea how to repair the code because I don't know where it went wrong. I have one error. Everything else compiles fine.
Re: Please help, my inventory code is not working
Remove either Object or DVD from the start of the statement with the error.
You can NOT put two data types with one variable. For example:
would be wrong with the two classnames (data types) before avar
Quote:
I have one error. Everything else compiles fine.
Comment out the statement with the error and see what happens.
Re: Please help, my inventory code is not working
OK I made some changes and I'm having some other issues now. Here is my code and below will be the error message I am getting.
Code Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package inventory1;
/**
*
* @author Gary
*/
public class Inventory1 {
public static void main(String[] args){
class dvd {
//private final String DVD;
//private final String DVD;
public dvd(int i, String DVD, int i0, double dvd) {
//this.DVD = DVD;
}
}
//DVD dvd;
Object DVD = new dvd (1, "Matrix", 5, 2.15);
System.out.println(DVD);
DVD = new dvd (2,"Aliens", 7, 1.23);
System.out.println(DVD);
DVD = new dvd (3, "Twilight", 6, 3.65);
System.out.println(DVD);
DVD = new dvd (4, "Hurt Locker", 3, 2.10);
System.out.println(DVD);
System.out.println("Product Title is " + dvd.getDvdTitle());
System.out.println("The number of units in stock is" + dvd.getDvdStock());
System.out.println("The price of each DVD is" + dvd.getDvdPrice());
System.out.println("The item number is " + dvd.getDvdItem());
System.out.println("The value of the inventory is" + dvd.value());
} //end main
} // end class Inventory1
class DVD {
private String dvdTitle;
private double dvdStock;
private double dvdPrice;
private double dvdItem;
public DVD(String title, double stock, double price, double item) {
dvdTitle = title;
dvdStock = stock;
dvdPrice = price;
dvdItem = item;
} //end four-argument constructor
// set DVD name
public void setDvdTitle(String title) {
dvdTitle = title;
} //end method setDvdTitle
//return DVD Title
public String getDvdTitle() {
return dvdTitle;
} //end method getDvdTitle
//set DVD Stock
public void setDvdStock(double stock) {
dvdStock = stock;
} //end method setDvdStock
//return DvdStock
public double getDvdStock() {
return dvdStock;
} //end method get Dvdstock
public void setDvdPrice(double price) {
dvdPrice = price;
} //end method setDvdPrice
//return dvdPrice
public double getDvdPrice() {
return dvdPrice;
} //end method get Dvd Price
public void setDvdItem(double item) {
dvdItem = item;
} //end method setdvdItem
//return DVD item
public double getDvdItem() {
return dvdItem;
} //end method getDvdItem
//calculate inventory value
public double value() {
return dvdPrice * dvdStock;
} //end method value
} //end class DVD
--- Update ---
Oh here are the errors:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
inventory1.Inventory1$1dvd@19189e1
inventory1.Inventory1$1dvd@1f33675
inventory1.Inventory1$1dvd@7c6768
inventory1.Inventory1$1dvd@1690726
at inventory1.Inventory1.main(Inventory1.java:47)
Java Result: 1
Re: Please help, my inventory code is not working
Can you copy and post here the compiler errors? What you have posted is from when you try to execute the code. Just compile the code and get the compiler errors. Don't try to execute the code when it has compiler errors.