JAVA-SE-Tutorial-codeswithpankaj
JAVA-SE-Tutorial-codeswithpankaj copied to clipboard
Java Assignment: Billing Stock System
trafficstars
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:
-
Create a class
Productwith the following attributes:- SKU (Unique Number)
- Product Name
- Product Quantity
- Single Product Price
-
Implement the following functionalities:
- Add multiple products.
- Search for a product using SKU and display the product details.
Input Section:
- Prompt the user to enter the SKU, Product Name, Product Quantity, and Single Product Price.
- Allow the user to add multiple products.
- After entering each product, ask the user if they want to add more products.
Output Section:
- Allow the user to search for a product using the SKU number.
- Display the total cost, product name, quantity, and single price of the searched product.
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:
- Create a
Productclass. - Create methods to add products and search products by SKU.
- Use appropriate data structures to store and manage products.
Instructions:
- Implement the
Productclass with appropriate attributes and methods. - Implement the
BillingStockSystemclass to manage product addition and searching. - Use
ArrayListto store the products. - Test the program by running it and ensuring the sample interaction works as expected.
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();
}
}
}
import java.util.Scanner;
public class BillingSalary {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter SKU(Unique number):");
int sku=sc.nextInt();
sc.nextLine();
System.out.println("Enter product name:");
String productname=sc.nextLine();
System.out.println("Enter product quantity:");
int quantity=sc.nextInt();
sc.nextLine();
System.out.println("Enter single book price:");
double singlePrice=sc.nextDouble();
sc.nextLine();
System.out.println("Do you want to add more[Y/N]:");
String addMore=sc.nextLine();
while(addMore.equalsIgnoreCase("Y")) {
System.out.println("Enter SKU(Unique number):");
int newSku=sc.nextInt();
sc.nextLine();
System.out.println("Enter product name:");
String newProductName=sc.nextLine();
System.out.println("Enter product quantity:");
int newQuantity=sc.nextInt();
sc.nextLine();
System.out.println("Enter single book price:");
double newSinglePrice=sc.nextDouble();
sc.nextLine();
System.out.println("Do you want to add more[Y/N]:");
addMore=sc.nextLine();
if(addMore.equalsIgnoreCase("Y")) {
System.out.println("Enter SKU(Unique number):");
sku=newSku;
System.out.println("Enter product name:");
productname=newProductName;
System.out.println("Enter product quantity:");
quantity=newQuantity;
System.out.println("Enter single book price:");
singlePrice=newSinglePrice;
}
}
System.out.println("------------Search Item------------------");
System.out.println("Enter product item form SKU no:");
int searchSku=sc.nextInt();
sc.nextLine();
if(sku==searchSku) {
System.out.println("Total cost:"+quantity*singlePrice+"/-");
System.out.println("Product Name:"+productname);
System.out.println("Quantity:"+quantity);
System.out.println("SinglePrice:"+singlePrice+"/-");
}else {
System.out.println("Item not found.");
}
}
}