Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Please help, my inventory code is not working

  1. #1
    Junior Member ggarrett's Avatar
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please help, my inventory code is not working

    I have been struggling with this program. It's an inventory program for class. It won't run and I need to modify it today with the following criteria Please help:

    Use an array to store the items. The output should 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.

    Create a method to calculate the value of the entire inventory.

    Create another method to sort the array items by the name of the product.

    My Code:
     
    package inventory1;
     
    /**
     *
     * @author Gary
     */
    public class Inventory1 {
     
     
     
        public static void main(String args []) {
     
            class dvd {
     
                public dvd(int i, String Matrix, int i0, double dvd) {
     
                }
     
        }
     
            DVD dvd;
            Object DVD dvd = new DVD (1, "Matrix", 5, 2.15);
     
            System.out.println(dvd);
     
     
            DVD dvd1 = new DVD (2,"Aliens", 7, 1.23);
     
            System.out.println(dvd);
     
     
            DVD = new dvd (3, "Twilight", 6, 3.65);
     
            System.out.println(dvd);
     
     
            DVD = new dvd (4, "Hurt Locker", 3, 2.10);
     
            System.out.println(dvd);
     
     
            System.out.println("Product Title is " + dvd.getDvdTitle());
     
            System.out.println("The number of units in stock is" + dvd.getDvdStock());
     
            System.out.println("The price of each DVD is" + dvd.getDvdPrice());
     
            System.out.println("The item number is " + dvd.getDvdItem());
     
            System.out.println("The value of the inventory is" + dvd.value());
      } //end main
     
     
    } // end class Inventory1
     
     
     
    class DVD {
     
        private String dvdTitle;
     
        private double dvdStock;
     
        private double dvdPrice;
     
        private double dvdItem;
     
     
        public DVD(String title, double stock, double price, double item) {
     
            dvdTitle = title;
     
            dvdStock = stock;
     
            dvdPrice = price;
     
            dvdItem  = item;
     
        } //end four-argument constructor
     
        // set DVD name
     
        public void setDvdTitle(String title) {
     
            dvdTitle = title;
     
        } //end method  setDvdTitle
     
        //return DVD Title
     
        public String getDvdTitle() {
     
            return dvdTitle;
     
        } //end method getDvdTitle
     
        //set DVD Stock
     
        public void setDvdStock(double stock) {
     
            dvdStock = stock;
     
        } //end method setDvdStock
     
     
     
        //return DvdStock
     
        public double getDvdStock() {
     
            return dvdStock;
     
        } //end method get Dvdstock
     
     
     
        public void setDvdPrice(double price) {
     
            dvdPrice = price;
     
        } //end method setDvdPrice
     
     
        //return dvdPrice
     
        public double getDvdPrice() {
     
            return dvdPrice;
     
        } //end method get Dvd Price
     
     
     
        public void setDvdItem(double item) {
     
            dvdItem = item;
     
        } //end method setdvdItem
     
     
     
        //return DVD item
     
        public double getDvdItem() {
            return dvdItem;
     
        } //end  method getDvdItem
     
     
     
        //calculate inventory value
     
        public double value() {
     
            return dvdPrice * dvdStock;
     
        } //end method value
     
     
    } //end class DVD


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,311
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Please help, my inventory code is not working

    It won't run
    Please explain. If you are getting errors, copy the full text of the messages and paste them here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member ggarrett's Avatar
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help, my inventory code is not working

    At line 26 it gives the following error:

    ';' expected

    required string, double, double, double

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,311
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Please help, my inventory code is not working

    Which line is line 26?

    What is "required string, double, double, double"?

    It'd be better if you posted the full text of the error message and not just copy a few lines.
    Please copy full text of error message and paste it here. Here is a sample:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member ggarrett's Avatar
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help, my inventory code is not working

    Line 26:

    [highlight=Java]

    Object DVD dvd = new DVD (1, "Matrix", 5, 2.15);

    [/hightlight]

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,311
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Please help, my inventory code is not working

    There are two data types at the start of the line: Object and DVD
    There should only be one. What data type do you want to define the variable: dvd to be?
    Remove the other data type.

    See this line:
       DVD dvd1 = new DVD

    The code looks like you tried many different ways to code it. Most of them are wrong.
    I suggest that you delete all of them and work on just one. Code it and then compile it.
    If there are errors, fix the errors and compile it again.
    Don't type in any more statements until all the errors are fixed.
    Work on ONE PROBLEM AT A TIME.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member ggarrett's Avatar
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help, my inventory code is not working

    Dude I have no idea how to repair the code because I don't know where it went wrong. I have one error. Everything else compiles fine.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,311
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Please help, my inventory code is not working

    Remove either Object or DVD from the start of the statement with the error.
    You can NOT put two data types with one variable. For example:
    String Scanner avar =...
    would be wrong with the two classnames (data types) before avar


    I have one error. Everything else compiles fine.
    Comment out the statement with the error and see what happens.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member ggarrett's Avatar
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help, my inventory code is not working

    OK I made some changes and I'm having some other issues now. Here is my code and below will be the error message I am getting.

     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package inventory1;
     
    /**
     *
     * @author Gary
     */
    public class Inventory1 {
     
     
     
        public static void main(String[] args){
     
            class dvd {
                //private final String DVD;
                //private final String DVD;
     
                public dvd(int i, String DVD, int i0, double dvd) {
                    //this.DVD = DVD;
                               }
     
        }
     
            //DVD dvd;
            Object DVD = new dvd (1, "Matrix", 5, 2.15);
     
            System.out.println(DVD);
     
            DVD = new dvd (2,"Aliens", 7, 1.23);
     
            System.out.println(DVD);
     
     
            DVD = new dvd (3, "Twilight", 6, 3.65);
     
            System.out.println(DVD);
     
     
            DVD = new dvd (4, "Hurt Locker", 3, 2.10);
     
            System.out.println(DVD);
     
     
            System.out.println("Product Title is " + dvd.getDvdTitle());
     
            System.out.println("The number of units in stock is" + dvd.getDvdStock());
     
            System.out.println("The price of each DVD is" + dvd.getDvdPrice());
     
            System.out.println("The item number is " + dvd.getDvdItem());
     
            System.out.println("The value of the inventory is" + dvd.value());
      } //end main
     
     
    } // end class Inventory1
     
     
     
    class DVD {
     
        private String dvdTitle;
     
        private double dvdStock;
     
        private double dvdPrice;
     
        private double dvdItem;
     
     
        public DVD(String title, double stock, double price, double item) {
     
            dvdTitle = title;
     
            dvdStock = stock;
     
            dvdPrice = price;
     
            dvdItem  = item;
     
        } //end four-argument constructor
     
        // set DVD name
     
        public void setDvdTitle(String title) {
     
            dvdTitle = title;
     
        } //end method  setDvdTitle
     
        //return DVD Title
     
        public String getDvdTitle() {
     
            return dvdTitle;
     
        } //end method getDvdTitle
     
        //set DVD Stock
     
        public void setDvdStock(double stock) {
     
            dvdStock = stock;
     
        } //end method setDvdStock
     
     
     
        //return DvdStock
     
        public double getDvdStock() {
     
            return dvdStock;
     
        } //end method get Dvdstock
     
     
     
        public void setDvdPrice(double price) {
     
            dvdPrice = price;
     
        } //end method setDvdPrice
     
     
        //return dvdPrice
     
        public double getDvdPrice() {
     
            return dvdPrice;
     
        } //end method get Dvd Price
     
     
     
        public void setDvdItem(double item) {
     
            dvdItem = item;
     
        } //end method setdvdItem
     
     
     
        //return DVD item
     
        public double getDvdItem() {
            return dvdItem;
     
        } //end  method getDvdItem
     
     
     
        //calculate inventory value
     
        public double value() {
     
            return dvdPrice * dvdStock;
     
        } //end method value
     
     
    } //end class DVD


    --- Update ---

    Oh here are the errors:
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
    inventory1.Inventory1$1dvd@19189e1
    inventory1.Inventory1$1dvd@1f33675
    inventory1.Inventory1$1dvd@7c6768
    inventory1.Inventory1$1dvd@1690726
    at inventory1.Inventory1.main(Inventory1.java:47)
    Java Result: 1

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,311
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Please help, my inventory code is not working

    Can you copy and post here the compiler errors? What you have posted is from when you try to execute the code. Just compile the code and get the compiler errors. Don't try to execute the code when it has compiler errors.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help with inventory program
    By curmudgeon in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 13th, 2013, 10:53 PM
  2. Null pointer exception in inventory program
    By tunrida in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 14th, 2012, 12:35 PM
  3. How to Translate working code into code with a Tester Class
    By bankoscarpa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 15th, 2012, 03:13 PM
  4. My code is not working
    By mike2452 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 9th, 2011, 07:17 AM
  5. Simple inventory System. Sometimes it doesn't update my added book.
    By JustinK in forum What's Wrong With My Code?
    Replies: 9
    Last Post: August 1st, 2011, 11:50 AM