Re: Help with inventory program
Quote:
Originally Posted by
ggarrett
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.
Re: Help with inventory program
Re: Help with inventory program
Quote:
Originally Posted by
ggarrett
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.
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:
Code java:
/*
* 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
Re: Help with inventory program
This is my code:
Code java:
/*
* 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
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.
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.
Code Java:
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
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?