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.
Thanks for the heads up.
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
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
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.
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
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?