Java "Inventory program" help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hamiltongreg
    New Member
    • Aug 2007
    • 6

    Java "Inventory program" help

    I am new to Java and am having problems getting my program to compile correctly.

    My assignment is as follows;
    Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software).
    • Create a product class that holds the item number, the name of the product, the number of units in stock, and the price of each unit.
    • Create a Java application that displays the product number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory (the number of units in stock multiplied by the price of each unit). Pay attention to the good programming practices in the text to ensure your source code is readable and well documented.

    Here is what I have so far
    Code:
    /** 
      *@author Greg Hamilton
      *Program was changed 31 Aug 07
      *The purpose of this program is to create a product class that holds an item number, name of the DVD movie, number of units in stock
      *and the price of each unit
    */
    
       import java.util.Scanner;
       import java.io.*;
       import java.util.*;
       
    
       public class Dvd extends Object
    
        {
    
         private String dvdTittle;
         private double dvdStock;
         private double dvdPrice;
         private double dvdItem;
    
         public Dvd( String tittle, double stock, double price, double item )
    
         {
           //implicit call to Object constructor occurs here
           dvdTittle = tittle;
           dvdStock = stock;
           dvdPrice = price;
           dvdItem = item;
          } //end four-argument constructor
     
    
    
          //set DVD name
          public void setdvdTittle( String tittle )
          {
              dvdTittle = tittle;
          } //end method setDvdTittle
    
          //return dvd Tittle
          public String getDvdTittle()
          {
            return dvdTittle;
          } //end method getDvdTittle
    
          //set Dvd stock
          public void setDvdStock( double stock)
          {
           dvdStock = ( stock < 0.0 ) ? 0.0 : stock;
          } //end method setDvdStock
    
          //return dvd stock
          public double getDvdStock()
          {
            return dvdStock;
          } //end method getDvdStock
    
         public void setDvdPrice( double price )
         {
            dvdPrice = ( price <0.0 ) ? 0.0 : price;
         } //end method SetDvdPrice
    
         //return dvd price
         public double getDvdPrice()
         {
           return dvdPrice;
         } //end method get Dvd Price
    
         public void setDvdItem( double item )
         {
           dvdItem = ( item <0.0) ? 0.0 : item;
         } //end method set dvd Item
         
         //return dvd item
         
         public double getDvdItem()
         {
           return dvdItem;
         } //end method getDvdItem
         
         
        // calculate inventory value
        public double value()
        {
           return dvdPrice * dvdStock;
    
        } //end method value
    
        //instantiate Collection object
            Dvd aDvd= new Dvd ("Dejavu", "10", "12.50", "101");  
    
    
     
         public static void main( String args[] )
    
           {
          
    
           
    
          System.out.printf("%s %s\n", "Product Tittle is",
             Dvd.gettittle() );
          System.out.printf("%s %s\n", "The number of units in stock is", 
             Dvd.getstock() );
          System.out.printf("%s %s\n", "The price of each DVD is",
             Dvd.getprice() );
          System.out.printf("%s %s\n", "The item number is",
             dvd.getitem() );
          System.out.printf("%s %s\n", "The value of the inventory is",
             Dvd.getvalue() );
    
          } //end main
    
       } //end class Dvd


    My complier does not like my Dvd aDVD = new Dvd(); statement. I filled in values to populate the data points required for the program.

    The error codes that I get are as follows;

    6 errors found:
    File: C:\Documents and Settings\Greg\D esktop\Dvd.java [line: 90]
    Error: C:\Documents and Settings\Greg\D esktop\Dvd.java :90: cannot find symbol
    symbol : constructor Dvd(java.lang.S tring,java.lang .String,java.la ng.String,java. lang.String)
    location: class Dvd
    File: C:\Documents and Settings\Greg\D esktop\Dvd.java [line: 102]
    Error: C:\Documents and Settings\Greg\D esktop\Dvd.java :102: cannot find symbol
    symbol : method gettittle()
    location: class Dvd
    File: C:\Documents and Settings\Greg\D esktop\Dvd.java [line: 104]
    Error: C:\Documents and Settings\Greg\D esktop\Dvd.java :104: cannot find symbol
    symbol : method getstock()
    location: class Dvd
    File: C:\Documents and Settings\Greg\D esktop\Dvd.java [line: 106]
    Error: C:\Documents and Settings\Greg\D esktop\Dvd.java :106: cannot find symbol
    symbol : method getprice()
    location: class Dvd
    File: C:\Documents and Settings\Greg\D esktop\Dvd.java [line: 108]
    Error: C:\Documents and Settings\Greg\D esktop\Dvd.java :108: cannot find symbol
    symbol : variable dvd
    location: class Dvd
    File: C:\Documents and Settings\Greg\D esktop\Dvd.java [line: 110]
    Error: C:\Documents and Settings\Greg\D esktop\Dvd.java :110: cannot find symbol
    symbol : method getvalue()
    location: class Dvd


    Thanks for any help that you can give me.
  • shaileshkumar
    New Member
    • Aug 2007
    • 36

    #2
    include zero argument constructor

    include the following piece of code in your code.
    public Dvd()
    {


    }

    The reason for this is compiler does not supply default constructor when there are parameterised constructors.
    Also
    you need not extend your class with Object class.
    It happens by default.



    with regards,
    shailesh
    Last edited by shaileshkumar; Sep 1 '07, 02:46 AM. Reason: exact answer

    Comment

    • hamiltongreg
      New Member
      • Aug 2007
      • 6

      #3
      Thanks for the pointers. I removed the extension for the object class.

      I don't mean to sound dense here, but when I added the public Dvd() and the braces in my code (at the end, before the print statments), I got a illegal start of expression error.

      Is there a specific place that I should have added the public DVD() in?

      Thanks again.

      Originally posted by shaileshkumar
      include the following piece of code in your code.
      public Dvd()
      {


      }

      The reason for this is compiler does not supply default constructor when there are parameterised constructors.
      Also
      you need not extend your class with Object class.
      It happens by default.



      with regards,
      shailesh

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by hamiltongreg
        Thanks for the pointers. I removed the extension for the object class.

        I don't mean to sound dense here, but when I added the public Dvd() and the braces in my code (at the end, before the print statments), I got a illegal start of expression error.

        Is there a specific place that I should have added the public DVD() in?

        Thanks again.
        You don't need to add a no-args constructor Dvd(); the error at line 90 is raised
        because you don't have a Dvd constructor that takes four Strings. Read that
        error message carefully and you'll see that this is exactly what the compiler
        is trying to tell you.

        You do have a Dvd constructor that takes one string and three doubles. That
        should ring a bell.

        The new errors you got is because of mismatched curly brackets.

        kind regards,

        Jos

        Comment

        • shaileshkumar
          New Member
          • Aug 2007
          • 36

          #5
          in hurry i gave you some irrelevant answer.

          Correct solution for your problem is:

          you have declared public Dvd(String,Floa t ,.........)
          but you have supplied all the strings as parameters in your code.


          remove double quotes for all parameters except the first one.

          Comment

          • shaileshkumar
            New Member
            • Aug 2007
            • 36

            #6
            Dvd aDvd= new Dvd ("Dejavu", 10, 12.50, 101);


            apart from these ,check spelling mistakes.

            Comment

            • shaileshkumar
              New Member
              • Aug 2007
              • 36

              #7
              few more corrections:


              call the methods like this
              aDvd.getDvDTitl e();
              aDvd.getDVDStoc k();

              Comment

              • shaileshkumar
                New Member
                • Aug 2007
                • 36

                #8
                //dear hamilton: you wont get any error now
                //completely corrected & excecuted code

                public class Dvd extends Object

                {

                private String dvdTittle;
                private double dvdStock;
                private double dvdPrice;
                private double dvdItem;
                public Dvd( String tittle, double stock, double price, double item )

                {
                //implicit call to Object constructor occurs here
                dvdTittle = tittle;
                dvdStock = stock;
                dvdPrice = price;
                dvdItem = item;
                } //end four-argument constructor



                //set DVD name
                public void setdvdTittle( String tittle )
                {
                dvdTittle = tittle;
                } //end method setDvdTittle

                //return dvd Tittle
                public String getDvdTittle()
                {
                return dvdTittle;
                } //end method getDvdTittle

                //set Dvd stock
                public void setDvdStock( double stock)
                {
                dvdStock = ( stock < 0.0 ) ? 0.0 : stock;
                } //end method setDvdStock

                //return dvd stock
                public double getDvdStock()
                {
                return dvdStock;
                } //end method getDvdStock

                public void setDvdPrice( double price )
                {
                dvdPrice = ( price <0.0 ) ? 0.0 : price;
                } //end method SetDvdPrice

                //return dvd price
                public double getDvdPrice()
                {
                return dvdPrice;
                } //end method get Dvd Price

                public void setDvdItem( double item )
                {
                dvdItem = ( item <0.0) ? 0.0 : item;
                } //end method set dvd Item

                //return dvd item

                public double getDvdItem()
                {
                return dvdItem;
                } //end method getDvdItem


                // calculate inventory value
                public double value()
                {
                return dvdPrice * dvdStock;

                } //end method value

                //instantiate Collection object




                public static void main( String args[] )

                {

                Dvd aDvd= new Dvd ("Dejavu", 10, 12.50, 101);


                System.out.prin tln("Product Tittle is"+ aDvd.getDvdTitt le() );
                System.out.prin tln("The number of units in stock is"+
                aDvd.getDvdStoc k() );
                System.out.prin tln("The price of each DVD is"+ aDvd.getDvdPric e() );
                System.out.prin tln( "The item number is"+ aDvd.getDvdItem ());
                System.out.prin tln( "The value of the inventory is"+ aDvd.value() );

                } //end main

                } //end class Dvd

                Comment

                • hamiltongreg
                  New Member
                  • Aug 2007
                  • 6

                  #9
                  Thank you so much for the help! Everything works now.

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by shaileshkumar
                    //dear hamilton: you wont get any error now
                    //completely corrected & excecuted code
                    You know, this forum's policy is *not* to spoonfeed code; don't do this again.
                    If you had read the forum guidelines (see the 'Help' link in the top-right corner
                    of this page, you could have known this).

                    It's too late now, the OP has been spoonfed; don't do this again. I won't make
                    this an official warning, but please cooperate with this forum's guidelines.

                    kind regards,

                    Jos

                    Comment

                    • hamiltongreg
                      New Member
                      • Aug 2007
                      • 6

                      #11
                      Sorry for creating a problem here with my questions.

                      I just wanted to let you know that the help I recived was invaluable to me. I had emailed my instructor for help (project was due Friday) and still haven't heard anything back.

                      I did not do well on the last project and this one was a real life saver for me.

                      I did not take it as being spoon feed with the posts (and in my case it helped me to figure out how close I was to what the code should have been). Seeing the full up code allowed me to regain my confidence and showed me where my thinking was flawed (quotes in wrong spots, mismatched {}).




                      Originally posted by JosAH
                      You know, this forum's policy is *not* to spoonfeed code; don't do this again.
                      If you had read the forum guidelines (see the 'Help' link in the top-right corner
                      of this page, you could have known this).

                      It's too late now, the OP has been spoonfed; don't do this again. I won't make
                      this an official warning, but please cooperate with this forum's guidelines.

                      kind regards,

                      Jos

                      Comment

                      • JosAH
                        Recognized Expert MVP
                        • Mar 2007
                        • 11453

                        #12
                        Originally posted by hamiltongreg
                        Sorry for creating a problem here with my questions.
                        You're not the cause of the 'problem'; that would be anthropic reasoning (google
                        for that). The other poster just shouldn't have posted complete code. Maybe in
                        your particular case it has helped you (a bit?) Most of the time, people simply
                        copy and paste the code and turn it in as if it were their own.

                        That is cheating; suppose such a cheater graduates and becomes your coworker.
                        You most certainly don't want that because you'll end up with almost a double
                        job: your own task plus correcting the mess created by that coworker.

                        That is one of the main reasons we don't supply anyone with complete code.

                        kind regards,

                        Jos

                        Comment

                        Working...