package cumpa;

import javax.sound.midi.Soundbank;
import java.util.Scanner;

public class App {

    //App variables
    private static String appName = "Our Groceries";
    private static double appVersion = 0.1;

    //Input scanner
    private static Scanner scanner = new Scanner(System.in);

    //our grocery item
    private static String itemName;
    private static String itemCategory;
    private static double itemUnitPrice;
    private static int itemUnits;
    private static double itemTotalPrice;

    private static void initApp(String name, double ver){
        System.out.println("Initializing " + name + " version " + ver);
    }

    private static void getItemDetails(){
        System.out.println("=== Input item details ===");
        System.out.print("Name: ");itemName = scanner.nextLine();
        System.out.print("Category: ");itemCategory = scanner.nextLine();
        System.out.print("Unit Price: ");itemUnitPrice = scanner.nextDouble();
        System.out.print("Units : ");itemUnits = scanner.nextInt();
        scanner.nextLine();
        System.out.println("======= End input ========");

        // some logic after input
        itemTotalPrice = itemUnitPrice * itemUnits;

    }

    private static void showItemDetails(){
        System.out.println("=== Our product ===");
        System.out.printf("Name: %s \n",itemName);
        System.out.printf("Category: %s \n",itemCategory);
        System.out.printf("Unit proice: %s \n",itemUnitPrice);
        System.out.printf("Total units: %s \n",itemUnits);
        System.out.printf("Total price: %s \n",itemTotalPrice);
        System.out.println("===================");
    }

    public static void main(String[] args) {

        initApp(appName,appVersion);

        //getItemDetails();
        //showItemDetails();

        int numberOfItems;

        System.out.print("How many items do you want to input: "); numberOfItems=scanner.nextInt();
        scanner.nextLine(); // this is needed because nextInt does not consume the new line character and the next input will be skipped

        for (int i=0;i<numberOfItems;i++){

            System.out.println("### Enter item  " + i);
            getItemDetails();
            showItemDetails();

        }

        System.out.println("Application finished");


    }

}

@@ -811,32 +811,34 @@
 Line();%0A        
+//
 System.out.print
@@ -887,32 +887,34 @@
 Line();%0A        
+//
 System.out.print
@@ -1165,16 +1165,18 @@
         
+//
 itemTota
@@ -1364,32 +1364,34 @@
 mName);%0A        
+//
 System.out.print
@@ -1425,32 +1425,34 @@
 egory);%0A        
+//
 System.out.print
@@ -1549,32 +1549,34 @@
 Units);%0A        
+//
 System.out.print
@@ -1807,32 +1807,44 @@
 ItemDetails();%0A%0A
+%0A        /*%0A
         int numb
@@ -1854,17 +1854,16 @@
 fItems;%0A
-%0A
         
@@ -2091,17 +2091,16 @@
 skipped%0A
-%0A
         
@@ -2259,24 +2259,480 @@
 %0A%0A        %7D%0A
+        */%0A        boolean _continue = true;%0A        int i=0;%0A        while (_continue)%7B%0A            i++;%0A            getItemDetails();%0A            showItemDetails();%0A            System.out.print(%22Enter another one%5By/N%5D : %22);%0A%0A            if (scanner.nextLine().toLowerCase().equals(%22y%22))%7B%0A                _continue=true;%0A%0A            %7Delse%7B%0A                _continue=false;%0A            %7D%0A        %7D%0A        System.out.println(%22You entered %22+i+%22 items.%22);%0A%0A
 %0A        Sys

Input with while