import java.util.Scanner;
public class Main
{
public static int Search (int[]arr, int k)
{
for (int i = 0; i < arr.length; i++)
{
if (arr[i] == k)
{
return i;
}
}
System.out.println ("The product is not found.");
return -1;
}
public static void main (String[]args)
{
Scanner in = new Scanner (System.in);
System.out.println ("Enter number of products: ");
int n = in.nextInt ();
Product[]p = new Product[n];
for (int i = 0; i < n; i++)
{
p[i].getpcode ();
p[i].getpcategory ();
p[i].getpwarranty ();
p[i].getpprice ();
}
for (int i = 0; i < n; i++)
{
p[i].display ();
}
int[] arr = new int[n];
for (int i = 0; i < n; i++)
{
arr[i] = p[i].getpcode ();
}
int pcd;
System.out.println ("Enter the product code for the product to delete:");
pcd = in.nextInt ();
int n2 = Search (arr, pcd);
arr[0] = 0;
System.out.println ("Please enter the product code to update: ");
int pcd2 = in.nextInt();
System.out.println ("Update the warranty? (y) Yes, (n) No (n)");
String a1 = in.next();
System.out.println ("Update the product price? (y) Yes, (n) No ");
String a2 = in.next();
System.out.println("Enter the new price for EliteBook");
double a3=in.nextDouble();
System.out.println("Update the stock level? (y) Yes, (n) No n ");
String a4=in.next();
System.out.println("Product details has been updated successfully!!!");
}
}
class Product
{
private int p_code;
private String p_category;
private String p_warranty;
private double p_price;
Scanner in = new Scanner (System.in);
public int getpcode ()
{
System.out.println ("Enter the product code: ");
p_code = in.nextInt ();
return p_code;
}
public void getpcategory ()
{
System.out.println ("Enter product category: ");
p_category = in.next ();
}
public void getpwarranty ()
{
System.out.println ("Enter the product warranty: ");
p_warranty = in.next ();
}
public void getpprice ()
{
System.out.println ("Enter the product price: ");
p_price = in.nextDouble ();
}
public void display ()
{
System.out.println ("Product code: " + p_code);
System.out.println ("Product category: " + p_category);
System.out.println ("Product warranty: " + p_warranty);
System.out.println ("Product price: " + p_price);
}
}
Comments
Leave a comment