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 8 of 8

Thread: Help with inventory program

  1. #1
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Help with inventory program

    Quote Originally Posted by ggarrett View Post
    Please tell me what I'm doing wrong.
    ....

    First consider editing your original post and wrapping your posted code in [code] [/code] tags so that it retains whatever formatting it has. Also tell us the specifics of just what the code is *supposed* to be doing, and the problems you may be having with it.


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

    Default Re: Help with inventory program

    Thanks for the heads up.

  3. #3
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Help with inventory program

    Quote Originally Posted by ggarrett View Post
    Thanks for the heads up.
    Thanks for the formatting, now for the rest of my request -- the details of your assignment and the problems with your current code.

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

    Default Re: Help with inventory program

    My assignment:

    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.

    My Error:

    Constructor DVD in class DVD cannot be applied to given type
    required: String double, double, double
    found: int, string, int, double

    --- Update ---

    This is my code:

     
    /*
     * 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 []) {
     
     
     
            DVD dvd;
     
     
            dvd = new DVD(1, "Bad Boys", 5, 2.15);
     
            System.out.println(dvd);
     
     
            dvd = new DVD (2, "Color Purple", 7, 1.23);
     
            System.out.println(dvd);
     
     
            dvd = new DVD (3, "Madea Family Reunion", 6, 3.65);
     
            System.out.println(dvd);
     
     
            dvd = new DVD (4, "Diary of a Mad Black Woman", 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

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

    Default Re: Help with inventory program

    This is my code:

     
    /*
     * 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 []) {
     
     
     
            DVD dvd;
     
     
            dvd = new DVD(1, "Bad Boys", 5, 2.15);
     
            System.out.println(dvd);
     
     
            dvd = new DVD (2, "Color Purple", 7, 1.23);
     
            System.out.println(dvd);
     
     
            dvd = new DVD (3, "Madea Family Reunion", 6, 3.65);
     
            System.out.println(dvd);
     
     
            dvd = new DVD (4, "Diary of a Mad Black Woman", 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

  6. #6
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Help with inventory program

    The error is telling you exactly what is wrong. Look at the order of the parameters declared in the DVD constructor. Now look at the order that you're using when you try to call the constructor. That order must match.

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

    Default Re: Help with inventory program

    I applied the suggested solutions, but it is still not running correctly. I have no errors but it is still not running. Code below.

     
    package inventory1;
     
    /**
     *
     * @author Gary
     */
    public class Inventory1 {
     
     
     
        public static void main(String args []) {
     
            class dvd {
     
                private dvd(int i, String bad_Boys, int i0, double d) {
                    throw new UnsupportedOperationException("Not yet implemented");
                }
     
        }
     
            DVD dvd = null;
            Object DVD = new dvd(1, "Bad Boys", 5, 2.15);
     
            System.out.println(dvd);
     
     
            DVD = new dvd (2, "Color Purple", 7, 1.23);
     
            System.out.println(dvd);
     
     
            DVD = new dvd (3, "Madea Family Reunion", 6, 3.65);
     
            System.out.println(dvd);
     
     
            DVD = new dvd (4, "Diary of a Mad Black Woman", 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 ---

    This is the message I'm getting now:

    Exception in thread "main" java.lang.UnsupportedOperationException: Not yet implemented
    at inventory1.Inventory1$1dvd.<init>(Inventory1.java: 20)
    at inventory1.Inventory1.main(Inventory1.java:26)
    Java Result: 1

  8. #8
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Help with inventory program

    Never mind that you have an unsupported method that you're calling (and the easy fix is to put some decent code in the method and get rid of the throw exception line), why are you creating a new dvd class when you already have a perfectly viable DVD class that you should be using there?

Similar Threads

  1. 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
  2. Program goes into infinite compilation. University project - Library Program.
    By clarky2006 in forum What's Wrong With My Code?
    Replies: 35
    Last Post: November 10th, 2012, 03:56 PM
  3. Replies: 1
    Last Post: July 8th, 2012, 10:23 AM
  4. how to run a java program..when the program using jar
    By miriyalasrihari in forum Java Theory & Questions
    Replies: 2
    Last Post: May 17th, 2012, 10:04 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, 10:50 AM