Pankaj-Str / JAVA-SE-Tutorial-codeswithpankaj

Pankaj-Str's GitHub, 'JAVA-SE-Tutorial-codeswithpankaj,' is a concise compendium of Java SE tutorials. Ideal for developers and learners, it offers clear and insightful code snippets, providing an efficient pathway to enhance Java programming skills. A valuable resource for mastering essential concepts
https://codeswithpankaj.com
32 stars 15 forks source link

Java Assignment: Billing Stock System #10

Open Pankaj-Str opened 1 month ago

Pankaj-Str commented 1 month ago

Java Assignment: Billing Stock System

Objective: Create a Java program to manage a Billing Stock System that allows users to input product details, store them, and later search for product information using SKU (Stock Keeping Unit) number.

Requirements:

  1. Create a class Product with the following attributes:

    • SKU (Unique Number)
    • Product Name
    • Product Quantity
    • Single Product Price
  2. Implement the following functionalities:

    • Add multiple products.
    • Search for a product using SKU and display the product details.

Input Section:

Output Section:

Sample Interaction:

--- Input Section ---
Enter SKU (Unique Number): 101
Enter Product Name: Books
Enter Product Quantity: 20
Enter Single Book Price: 120/-

Do you want to add more [Y/N]: Y
Enter SKU (Unique Number): 102
Enter Product Name: Toy
Enter Product Quantity: 5
Enter Single Book Price: 560/-

Do you want to add more [Y/N]: Y
Enter SKU (Unique Number): 103
Enter Product Name: Samosa
Enter Product Quantity: 250
Enter Single Book Price: 20/-

Do you want to add more [Y/N]: N

--- Output Section ---
------ Search Item ------
Enter Product Item Form SKU No .: 103
Total Cost: 5000/-
Product Name: Samosa
Quantity: 250
Single Price: 20/-

Guidelines:

  1. Create a Product class.
  2. Create methods to add products and search products by SKU.
  3. Use appropriate data structures to store and manage products.

Instructions:

  1. Implement the Product class with appropriate attributes and methods.
  2. Implement the BillingStockSystem class to manage product addition and searching.
  3. Use ArrayList to store the products.
  4. Test the program by running it and ensuring the sample interaction works as expected.
AlokSingh100 commented 1 month ago
package consta;

import java.util.*;

public class product {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int sku2,price2,quantity2,a=0;
        String pname2,yN;
        System.out.println("--- Input Section ---");
        int[] sku1=new int[100];
        int[] price1=new int[100];
        int[] quentity1=new int[100];
        String[] pro_name=new String[100];
        for (int i = 0; i < sku1.length; i++) {
            a++;
            System.out.print("Enter SKU (Unique Number): " );
            sku2=scanner.nextInt();
            sku1[i]=sku2;
            System.out.print("Enter Product Name: ");
            pname2=scanner.next();
            pro_name[i]=pname2;
            System.out.print("Enter "+pname2+" Quantity: ");
            quantity2=scanner.nextInt();
            quentity1[i]=quantity2;
            System.out.print("Enter Single "+pname2+" Price: ");
            price2=scanner.nextInt();
            price1[i]=price2;
            System.out.println();
            System.out.print("Do you want to add more [Y/N] ");
            yN=scanner.next();
            if (yN.equals("Y")||yN.equals("y"))
                continue;
            else if (yN.equals("n")||yN.equals("N")) {
                break;
            }
        }

        int[] sku5=new int[a];
        System.arraycopy(sku1, 0, sku1, 0, a);
        block_chain bencho=new block_chain(sku1,pro_name,quentity1,price1,a);
        bencho.print();
        System.out.println("------ Search Item ------");
        bencho.search();
    }

    static class block_chain {
       int[] sku;
       int[] quantity;
       int[] price;
       String[] pname;
       int aa;
       block_chain(int[] sku,String[] pname,int[] quantity,int[] price,int aa){
           this.sku=sku;
           this.quantity=quantity;
           this.price=price;
           this.pname=pname;
           this.aa=aa;
       }
       void print(){
           int dbs= sku.length;
           for (int i = 0; i < aa; i++) {
               System.out.println();
               System.out.println("Your SKU is ="+sku[i]);
               System.out.println("Your Product name is "+pname[i]);
               System.out.println("Your Quantity is" + quantity[i]);
               System.out.println("Price of Single Product is "+ price[i]);
               System.out.println();
           }
       }
       void search(){
           int a=0,b=0;
           Scanner scanner=new Scanner(System.in);

           System.out.print("Enter Product Item Form SKU No ");
           a=scanner.nextInt();
           for (int i = 0; i < sku.length; i++) {
               if (sku[i]==a){
                   b=i;
                   break;
               }
           }
               System.out.println("Your Product name is "+pname[b]);
               System.out.println("Your Quantity is" + quantity[b]);
               System.out.println("Price of Single Product is "+ price[b]);

       }

   }

    public static class product1 {
        public static void main(String[] args) {
            Scanner scanner=new Scanner(System.in);
            int sku2,price2,quantity2,a=0;
            String pname2,yN;
            System.out.println("--- Input Section ---");
            int[] sku1=new int[100];
            int[] price1=new int[100];
            int[] quentity1=new int[100];
            String[] pro_name=new String[100];
            for (int i = 0; i < sku1.length; i++) {
                a++;
                System.out.print("Enter SKU (Unique Number): " );
                sku2=scanner.nextInt();
                sku1[i]=sku2;
                System.out.print("Enter Product Name: ");
                pname2=scanner.next();
                pro_name[i]=pname2;
                System.out.print("Enter "+pname2+" Quantity: ");
                quantity2=scanner.nextInt();
                quentity1[i]=quantity2;
                System.out.print("Enter Single "+pname2+" Price: ");
                price2=scanner.nextInt();
                price1[i]=price2;
                System.out.println();
                System.out.print("Do you want to add more [Y/N] ");
                yN=scanner.next();
                if (yN.equals("Y")||yN.equals("y"))
                    continue;
                else if (yN.equals("n")||yN.equals("N")) {
                    break;
                }
            }
            int[] sku5=new int[a];
            consta.product.block_chain bencho=new consta.product.block_chain(sku1,pro_name,quentity1,price1,a);
            bencho.print();
            System.out.println("------ Search Item ------");
            bencho.search();
        }
    }
}