Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA PROGRAM MATERIAL: Array l. 2. Method Please make a simple storage program w

ID: 3781861 • Letter: J

Question

JAVA PROGRAM MATERIAL: Array l. 2. Method Please make a simple storage program with the following conditions: 1. The program begins by asking input quantity of goods that could be store in the storage. Validate input is between 1 and 10. 2. Then show menu following Menu 1 for adding goods into storage. Menu 2 for showing all of goods in the storage. Menu 3 for searching goods based on code. Menu 4 for exiting from program. 3. f user chooses menu "1", then program will ask to input Goods Name Goods Quantity Validate user can't input if storage is full. 4. f user chooses menu "2", then show goods data including code of goods (obtained based on order entry of goods, name of goods, and quantity of goods in the storage 5. If user chooses menu "3" then the program will: Ask user to input code of goods. Validate input is only between 1 and the quantity of goods in the storage. Display goods code, goods name and quantity of goods. 6. f user chooses menu "4", then the program will ends Please run the EXE file to see the sample program. Print Screen of the Beginning of the Program Binus Online Storage Input maximal quantity of your storage C1..10] 5

Explanation / Answer

GoodsTest.java

import java.util.Scanner;


public class GoodsTest {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.println("Binus Online Storage");
       System.out.println("Input maximal quantity of your storage [1..10]: ");
       int n = scan.nextInt();
       while(n <=0 || n >=10){
           System.out.println("Invalid Input. Input maximal quantity of your storage [1..10]: ");
           n = scan.nextInt();
       }
       int count = 0;
       int quantity[] = new int[n];
       String name[] = new String[n];
       while(true){
       System.out.println("Menu === 1. Add goods 2. See goods 3. Search goods 4. Exit Choice: ");
       int choice = scan.nextInt();
       if(choice == 1){
          
           addGoods(name, quantity, scan, count);
           count++;
       }
       else if(choice == 2){
           displayGoods(name, quantity,count);
       }
       else if(choice == 3){
           searchGoods(name, quantity, scan,count);
       }
       else if(choice == 4){
           System.out.println("Thank you for using Binus Online Storage Service");
           break;
       }
       }
   }
   public static void addGoods(String name[], int quantity[], Scanner scan, int count){
       System.out.print("Input your goods name number "+(count+1)+": ");
       String n = scan.next();
       System.out.print("Input your quantity number "+(count+1)+": ");
       int num = scan.nextInt();
       name[count] = n;
       quantity[count] = num;
   }
   public static void displayGoods(String name[], int quantity[],int count){
       System.out.println("No. Name Quantity ============================================= ");
       for(int i=0; i<count; i++){
           System.out.println((i+1)+" "+name[i]+" "+quantity[i]);
       }
   }
   public static void searchGoods(String name[], int quantity[], Scanner scan,int count){
       System.out.print("Input number of goods that you want to search [1.."+count+"]: ");
       int n = scan.nextInt();
       System.out.println("No. Name Quantity ============================================= ");
           System.out.println((n)+" "+name[n-1]+" "+quantity[n-1]);
   }
}

Output:

Binus Online Storage
Input maximal quantity of your storage [1..10]:
5
Menu
===
1. Add goods
2. See goods
3. Search goods
4. Exit
Choice:
1
Input your goods name number 1: Pencil
Input your quantity number 1: 5
Menu
===
1. Add goods
2. See goods
3. Search goods
4. Exit
Choice:
1
Input your goods name number 2: Pen
Input your quantity number 2: 6
Menu
===
1. Add goods
2. See goods
3. Search goods
4. Exit
Choice:
2
No.   Name   Quantity
=============================================

1   Pencil   5
2   Pen   6
Menu
===
1. Add goods
2. See goods
3. Search goods
4. Exit
Choice:
3
Input number of goods that you want to search [1..2]: 1
No.   Name   Quantity
=============================================

1   Pencil   5
Menu
===
1. Add goods
2. See goods
3. Search goods
4. Exit
Choice:
4
Thank you for using Binus Online Storage Service