Answer to Question #238289 in Java | JSP | JSF for Princess

Question #238289
The user must have the option to delete a product that has been saved. The user must first enter the product code to be deleted. Next, the user must confirm whether they

want to delete the product.

Q.1.10 The user must also have the ability to update specific details of the product. For

example, the user must first enter the product code and then confirm whether to

update the following product details:

Update the product warranty.

Update the product price.

Update the product stock level.

Please enter the product code to update: ASS Update the warranty? (y) Yes, (n) No n Opdate the product price? (y) Yes, (n) No y Enter the new price for EliteBook >> 14500 Update the stock level? (y) Yes, (n) No n Product details has been updated successfully!!!

Enter (1) to launch menu or any other key to exit
1
Expert's answer
2021-09-17T05:08:28-0400
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);


} 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS