I can not figure out how to use an array to store the different things and the total is only showing 0.0 instead of the total of the inventory. Can I please get some help on this?
Code:
// This calls the external class scanner
import java.util.Scanner;
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
Comment