I am not trying to be mean, but there are so many things wrong in your code that I don't really know where to begin. Are you taking a class in Java? If so, then you really should sit down with your instructor. If not, then you need to get a good book and work through it.
Again, I want to stress that I'm not trying to be mean. Most of the mistakes that you are making are made by all of us when we first learn. You just seem to have made them all at once.
Let me start by posting some code that does the same thing that yours does. It is NOT a finished product, and will NOT produce any output. But neither did yours. I hope it will give you something to compare your code to, and perhaps I can answer questions from there.
I hope this helps. tom
publicclass Product {
//instance variables are private
private String category;
private String favourite;
privateint qtyPrepared;
privateint qtySold;
privateint costPrice;
privateint sellingPrice;
privateint totalCostPrice;
privateint totalSellingPrice;
privateint difference;
//Constructor to constuct an object of the class the proper way.
public Product(String cat, String fav, int prepared, int sold, int price)
{
category = cat;
favourite = fav;
qtyPrepared = prepared;
qtySold = sold;
sellingPrice = price;
totalCostPrice = c1.qtyPrepared * c1.costPrice;
totalSellingPrice = c1.qtySold * c1.sellingPrice;
difference = c1.totalSellingPrice - c1.totalCostPrice;
}
//Still need accessor methods, and maybe some mutator methods.
}
//should be a separate file
publicclass MainDisplay {
publicstaticvoid main(String[] args) {
//I created 3 arrays, but you could get by with just one.
//These lines create the arrays
Product[] computers = new Product[3];
Product[] printers = new Product[2];
Product[] scanners = new Product[2];
//these lines create the Product objects in the arrays.
computers[0] = new Product("Computer", "DELL", 0, 0, 1000, 1700);
computers[1] = new Product("Computer", "Compaq", 0, 0, 900, 1200);
computers[2] = new Product("Computer", "HP", 0, 0, 1200, 1500);
printers[0] = new Product ("Printer", "Digitech", 0, 0, 150, 200);
printers[1] = new Product ("Printer", "HP", 0, 0, 180, 300);
scanners[0] = new Product("Scanner", "HP", 0, 0, 100, 150);
scanners[0] = new Product("Scanner", "Digitech", 0, 0, 80, 120);
}
}