help with an array
- From: "porky008" <porky008@xxxxxxxxxxx>
- Date: 30 Oct 2006 12:08:52 -0800
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.
// This calls the external class scanner
import java.util.Scanner;
// This is the class to hold things
class inventory
{ // start of class
// Variable Declaration
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
// gets the product name
public void getproductname(String productname)
{
productname = productname;
}
// gets the product number
public void setproductnumber(double productnumber)
{
productnumber = productnumber;
}
public double getproductnumber()
{
return productnumber;
}
// gets the number in stock
public void setnumberinstock(double numberinstock)
{
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
public double value()
{
return numberinstock * priceofitem;
}
} // end of class
*****************************************************************
// This calls the external class scanner
import java.util.Scanner;
public class whatever
{ // starts the class
public static void main( String args[])
{ // starts the program
Scanner input = new Scanner( System.in );
inventory myinventory = new inventory();
// get the name of the movie
System.out.printf( "\n\nEnter the name of the movie, enter stop
when done):");
String productname = (input.next());
while(!productname.equals("stop"))
{ // should start the loop
// gets the product number for the movie
System.out.printf( "\nEnter the product number: " );
myinventory.setproductnumber(input.nextDouble());
// gets the number you are puting into stock
System.out.printf( "\nEnter the number in stock: ");
myinventory.setnumberinstock(input.nextDouble());
// gets the price of the movie
System.out.printf( "\nEnter the items price: ");
myinventory.setpriceofitem(input.nextDouble());
// this should show the value of the inventory
System.out.printf( "\n\nThis is what the value of the inventory
should be: $ "+ myinventory.value());
// get the name of the movie
System.out.printf( "\n\nEnter the name of the movie, enter stop
when done):");
myinventory.getproductname(input.next());
} // should end the loop
} // end of program
} // end of class
.
- Follow-Ups:
- Re: help with an array
- From: RedGrittyBrick
- Re: help with an array
- Prev by Date: Java usercontrol?
- Next by Date: Re: help with an array
- Previous by thread: Java usercontrol?
- Next by thread: Re: help with an array
- Index(es):
Relevant Pages
|