The moderator posted this in another thread:
(I am starting a new one not to confuse the other subject at hand)
".java classes are compiled to into .class files. If you have a .java file called Product.java, when you compile it a .class is created for every class in the file Product.java if there are no errors. In this case you are getting this error because there is no class file called Product.class so you must compile the Product class first."
I don't really understand how to do this. When I go to the Command Prompt and type in the instructions given to create the .java file it creates a .class file, but then when I try to run it, it doesn't work and I get the same error.
This is the info I have and am not sure if it all goes in the Java file or in two separate files:
//Product1 class
public class Product1 {
private String title;
private double item;
private double stock;
private double price;
//Constructor to initialize product information
public Product(String title, double item, double stock, double price) {
setTitle(title) ;
setItem(item);
setStock(stock) ;
setPrice(price) ;
}
// Method to get title
public String getTitle() {
return title;
}
// Method to get item number
public double getItem() {
return item;
}
// Method to get stock
public double getStock() {
return stock;
}
// Method to get price
public double getPrice() {
return price;
}
// Method to set title name
public void setTitle(String title) {
this.title = title;
}
// Method to set item number
public void setItem(double item) {
this.item = item;
}
// Method to set stock available
public void setStock(double stock) {
this.stock = stock;
}
// Method to set price
public void setPrice(double price) {
this.price = price;
}
// Method to compute value of inventory
public double getInvValue() {
return this.stock *this.price;
}
}//end class Product1
//Inventory program
public class Inventory
{
public static void main (String args [])
{
System.out.prin tln ("Inventory of DVD Movies:\n");
String title = "Notebook";
double item = 1;
double stock = 27;
double price = 19.00;
double value;
Product product = new Product (title, item, stock, price);
System.out.prin tf("%s%18s\n", "DVD Title:", product.getTitl e() );
System.out.prin tf("%s%16s\n", "Item #:", product.getItem () );
System.out.prin tf("%s%8s\n", "Number in Stock:", product.getStoc k() );
System.out.prin tf("%s%18s\n", "Price:", product.getPric e() );
System.out.prin tf("%s%9s\n", "Inventory Value:", product.getInvV alue() );
}
}//end class Inventory
Thanks! ITQUEST
(I am starting a new one not to confuse the other subject at hand)
".java classes are compiled to into .class files. If you have a .java file called Product.java, when you compile it a .class is created for every class in the file Product.java if there are no errors. In this case you are getting this error because there is no class file called Product.class so you must compile the Product class first."
I don't really understand how to do this. When I go to the Command Prompt and type in the instructions given to create the .java file it creates a .class file, but then when I try to run it, it doesn't work and I get the same error.
This is the info I have and am not sure if it all goes in the Java file or in two separate files:
//Product1 class
public class Product1 {
private String title;
private double item;
private double stock;
private double price;
//Constructor to initialize product information
public Product(String title, double item, double stock, double price) {
setTitle(title) ;
setItem(item);
setStock(stock) ;
setPrice(price) ;
}
// Method to get title
public String getTitle() {
return title;
}
// Method to get item number
public double getItem() {
return item;
}
// Method to get stock
public double getStock() {
return stock;
}
// Method to get price
public double getPrice() {
return price;
}
// Method to set title name
public void setTitle(String title) {
this.title = title;
}
// Method to set item number
public void setItem(double item) {
this.item = item;
}
// Method to set stock available
public void setStock(double stock) {
this.stock = stock;
}
// Method to set price
public void setPrice(double price) {
this.price = price;
}
// Method to compute value of inventory
public double getInvValue() {
return this.stock *this.price;
}
}//end class Product1
//Inventory program
public class Inventory
{
public static void main (String args [])
{
System.out.prin tln ("Inventory of DVD Movies:\n");
String title = "Notebook";
double item = 1;
double stock = 27;
double price = 19.00;
double value;
Product product = new Product (title, item, stock, price);
System.out.prin tf("%s%18s\n", "DVD Title:", product.getTitl e() );
System.out.prin tf("%s%16s\n", "Item #:", product.getItem () );
System.out.prin tf("%s%8s\n", "Number in Stock:", product.getStoc k() );
System.out.prin tf("%s%18s\n", "Price:", product.getPric e() );
System.out.prin tf("%s%9s\n", "Inventory Value:", product.getInvV alue() );
}
}//end class Inventory
Thanks! ITQUEST
Comment