Re: help with an array
- From: RedGrittyBrick <RedGrittyBrick@xxxxxxxxxxxxx>
- Date: Mon, 30 Oct 2006 20:55:15 +0000
porky008 wrote:
This is what I have done so fare but I need to use an array to store
items. The output needs to 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. I have done this last part but it only brings up
0.0 instead of the total.
<useless comments snipped>
import java.util.Scanner;
class inventory
private String productname; // name of movie
private double productnumber; // product number
private double numberinstock; // number of movie in stock
private double priceofitem; // the price of the movie
public void getproductname(String productname)
That should be setproductname (or it should'n be void and the body should retyrn productname)
{
productname = productname;
Unless I am mistaken, that's not going to do anything. Maybe you meant
this.productname = productname;
}
// gets the product number
public void setproductnumber(double productnumber)
{
productnumber = productnumber;
this.productnumber = productnumber;
}
public double getproductnumber()
{
return productnumber;
}
// gets the number in stock
public void setnumberinstock(double numberinstock)
Comments like this are harmful, not helpful, they confuse the reader. Is it a setter or a getter?
{
numberinstock = numberinstock;
}
public double getnumberinstock()
{
return numberinstock;
}
// gets the price of the item
public void setpriceofitem(double priceofitem)
{
priceofitem = priceofitem;
}
public double getpriceofitem()
{
return priceofitem;
}
// This calculates the value of inventory, but i can not get it
to work
Probably because of the above-noted defect in your setters.
public double value()
{
return numberinstock * priceofitem;
}
} // end of class
<snip>
.
- References:
- help with an array
- From: porky008
- help with an array
- Prev by Date: help with an array
- Next by Date: Re: to open new window of JSP on the applet
- Previous by thread: help with an array
- Index(es):