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();

        }
        */
        boolean _continue = true;
        int i=0;
        while (_continue){
            i++;
            getItemDetails();
            showItemDetails();
            System.out.print("Enter another one[y/N] : ");

            /*
            if (scanner.nextLine().toLowerCase().equals("y")){
                _continue=true;

            }else{
                _continue=false;
            }
            */

            switch (scanner.nextLine().toLowerCase()){
                case  "y":
                    _continue=true;
                    break;
                case  "n":
                    _continue=false;
                    break;
                case "":
                    _continue=false;
                    break;
                default:
                    _continue=false;
                    System.out.println("Invalid Option");
            }
        }
        System.out.println("You entered " + i + " items.");


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


    }

}

@@ -664,20 +664,27 @@
  static 
-void
+GroceryItem
  getItem
@@ -686,32 +686,79 @@
 tItemDetails()%7B%0A
+        GroceryItem item = new GroceryItem();%0A%0A
         System.o
@@ -842,90 +842,21 @@
 item
-Name = scanner.nextLine();%0A        //System.out.print(%22Category: %22);itemCategory =
+.setItemName(
  sca
@@ -862,32 +862,33 @@
 anner.nextLine()
+)
 ;%0A        //Syst
@@ -873,34 +873,32 @@
 ine());%0A        
-//
 System.out.print
@@ -907,14 +907,10 @@
 Unit
+s
  
-Price
 : %22)
@@ -918,79 +918,22 @@
 item
-UnitPrice = scanner.nextDouble();%0A        System.out.print(%22Units : %22);
+.setItemUnits(
 item
@@ -949,32 +949,33 @@
 canner.nextInt()
+)
 ;%0A        scanne
@@ -1059,88 +1059,20 @@
     
-// some logic after input%0A        //itemTotalPrice = itemUnitPrice * itemUnits;%0A
+return item;
 %0A   
@@ -1107,32 +1107,48 @@
 showItemDetails(
+GroceryItem item
 )%7B%0A        Syste
@@ -1233,924 +1233,235 @@
 item
-Name);%0A        //System.out.printf(%22Category: %25s %5Cn%22,itemCategory);%0A        //System.out.printf(%22Unit proice: %25s %5Cn%22,itemUnitPrice);%0A        System.out.printf(%22Total units: %25s %5Cn%22,itemUnits);%0A        //System.out.printf(%22Total price: %25s %5Cn%22,itemTotalPrice);%0A        System.out.println(%22===================%22);%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        initApp(appName,appVersion);%0A%0A        //getItemDetails();%0A        //showItemDetails();%0A%0A%0A        /*%0A        int numberOfItems;%0A        System.out.print(%22How many items do you want to input: %22); numberOfItems=scanner.nextInt();%0A        scanner.nextLine(); // this is needed because nextInt does not consume the new line character and the next input will be skipped%0A        for (int i=0;i%3CnumberOfItems;i++)%7B%0A%0A            System.out.println(%22### Enter item  %22 + i);%0A            getItemDetails();%0A            showItemDetails();%0A%0A        %7D%0A        */
+.getItemName());%0A        System.out.printf(%22Total units: %25s %5Cn%22,item.getItemUnits());%0A        System.out.println(%22===================%22);%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        initApp(appName,appVersion);%0A
 %0A   
@@ -1563,16 +1563,35 @@
         
+ GroceryItem item =
  getItem
@@ -1621,32 +1621,36 @@
 showItemDetails(
+item
 );%0A            S
@@ -1700,201 +1700,8 @@
 );%0A%0A
-            /*%0A            if (scanner.nextLine().toLowerCase().equals(%22y%22))%7B%0A                _continue=true;%0A%0A            %7Delse%7B%0A                _continue=false;%0A            %7D%0A            */%0A%0A
     

Change the get Item detials and show item details to use an object of the new created class