Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / October 2006

Tip: Looking for answers? Try searching our database.

help with an array

Thread view: 
porky008 - 30 Oct 2006 21:08 GMT
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
RedGrittyBrick - 30 Oct 2006 21:55 GMT
> 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
[quoted text clipped - 3 lines]
> 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;
[quoted text clipped - 15 lines]
>        // 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>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.