I am trying to generate a list of a inventory in all products grabbed from an Array List.
The issue i am running into is how to create the headings/ titles for the list to categorize each product info grabbed from in a WHILE loop .
I am trying to come up with something like this :
But I am getting the following:
Want to know if there is a way i can add 1 single line on top for headings for category for each product info without it repeating in the while loop.
Here is the code used to display this list.
String menuChoice = getData.getString("(1)- Locate a single product item \n" + "(2)- Print active database inventory reprot \n" + "(3)- Print deleted products inventory report");
switch(menuChoice) {
case "1" :
// create Product object to call methods from product.
itemname = getData.getString("Please enter the product name you wish to view");
pb.search(itemname);
if (! pb.inList() )
JOptionPane.showMessageDialog(null, "no product or no database for product found ");
else {
Product po = pb.getProduct();
String str = "\tProduct Information\n" + "\n"+ "\n" + "(Product Name): "+ po.getProduct()+"\n" + "(Product Cost): "+ "$" + po.getPrice() +"\n"+ " " +"(Quantity):" + po.getQuantity();
display(str , "Product Database" , JOptionPane.INFORMATION_MESSAGE);
}
break; // Leave breaks before Case , outside of current case brackets ,
case "2" :
// Create Inventory report for active products
ArrayList list = pb.getList();
if (list.isEmpty())
JOptionPane.showMessageDialog(null, "Product inventory list is empty");
else {
JOptionPane.showMessageDialog(null, "Product \t " + "Quantity \t" + " " +"Price \t" +"Manufacturer\t" + " State" );// still have to add purchase Date field.
int i = 0 , length = pb.getSize();
String s = "";
while (i < length) {
Product pr = (Product)list.get(i);
s = s + pr.getProduct() + "\t" + pr.getQuantity() +"\t" + " " + pr.getPrice() +"\t"+ pr.getCompany().getName() +"\t" +pr.getCompany().getAddress().getState() + "\n";
i++;
}
display (s ," Product Quantity Price Manufacturer State" , JOptionPane.INFORMATION_MESSAGE);
}
break;
}