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

Question #235922
Q.1.8

The user must have the ability to search for a product. The user will select menu item two (2), which will prompt the user to enter a product code. If a valid product is found in the application, then display the product details to the user. If no valid product is found, display an error message to the user that the product cannot be located.

Sample Product Search Screenshot

Please enter the product code to search: 235

PRODUCT SEARCH RESULTS

PRODUCT CODE:

PRODUCT NAME:

PRODUCT WARRANTY:

PRODUCT CATEGORY: PRODUCT PRICE:

PRODUCT STOCK LEVELS:

PRODUCT SUPPLIER:

ASS

Laptop

2 years a 15000

3

IT 4 Africa

Enter (4) to launch menu or any other key to exit

Sample Invalid Product Screenshot

Please enter the product code to search: 1 The product cannot be located. Invalid Product Enter (1) to launch menu or any other key to exit
1
Expert's answer
2021-09-12T18:48:39-0400
import java.util.Scanner;
public class Main
{
    public static void Search(int[] arr, int k){    
        for(int i=0;i<arr.length;i++){    
            if(arr[i] == k){    
                System.out.println("The product is found.");
                break;
            }    
        }    
        System.out.println("The product is not found.");    
    }   
	public static void main(String[] args) {
	    Scanner in=new Scanner(System.in);
		int[] arr= {121,122,123,124,125,126,127};  
		System.out.println("Enter the product code to search:");
		int product_code=in.nextInt();
		
		Search(arr,product_code);
		
	}
}

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