You need to press A store has different categories of products in stock shown below TCS Code

A store has different categories of products in stock as shown below.
Item Number=[101, 102, 103, 108]
Item Name=[Milk, Cheese , Ghee, Bread]
Price=[42, 50, 500, 40]
Stock =[10, 20, 15, 16]

When user give input with 2 values as

  1. Item number for item which user wish to buy
  2. Quantity for the item entered above

When user enters above input, the code should check the stock

  1. If quantity is less than stock and item is available display a notification message showing Output Line1 [prices] INR Calculate total price in float with precision. Output Line2 quantity LEFT // updated stock for item after after purchase

2.If the quantity and stocks less than quantity entered by the user while placing order, then display message
Output Line1 NO STOCK

Output Line2 quantity LEFT

3.If user enter character as input for item number and quantity or enter item number which is not available then display following message and stop Output Line1- INVALID INPUT Make sure the string message displayed in output.

Sample INPUT :-

101
4

Sample OUTPUT:-

168.0 INR
6 LEFT

Sample INPUT :-

104
20

Sample OUTPUT:-

NO STOCK
16 LEFT

Solution in Java

import java.util.*;
public class codechef {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int[] item_number = {101,102,103,104};
        String[] item_name = {"Milk", "Cheese", "Ghee", "Bread"};
        int[] price = {42,50,500,40};
        int[] stock = {10,20,15,16};

    int item_num = sc.nextInt();
    int quant = sc.nextInt();
    int temp =0,flag=0;;
    for(int i = 0; i<4 ;i++) {
        if(item_num ==item_number[i]) {             
        temp = i;   
        flag=1;
        }
        }


    if(flag== 0){
    System.out.println("INVALID INPUT");
    System.exit(0);
    }
    if(quant > stock[temp]) {
        System.out.println("NO STOCK");
        System.out.println(stock[temp]+" "+"LEFT");
    }else if(quant <= stock[temp]){
    System.out.println((float)(price[temp]*quant)+" "+"INR");
    System.out.println(stock[temp]-quant+" "+"LEFT");
    }
    }
    }

Additional Reading

Also Read:

Acids, Bases and Salts-MCQ

Amazon Quiz MCQ Type Questions

Accenture MCQ Model Question Paper For 2022

Accenture MCQ Quantitative Aptitude Questions And Answers

Accenture MCQ Aptitude Questions And Answers

Top 30 MCQs for Your Data Science Interviews

Data Science MCQs For Written Exam

Time and Work Aptitude MCQ Questions & Answers for Infosys,TCS,Wipro

Core Java Multiple Choice Questions With Answers 2022

Infosys Mcq types Aptitude Questions for 2022

Latest Wipro MCQ Placement Paper

TCS Ninja Programming MCQ Questions with Answers

Amazon Aptitude Questions and Answers 2022

Data Science MCQ Questions 2022

Check Also

How to debugg our flutter application

Debugging a Flutter application involves a variety of techniques and tools to identify and fix …

Leave a Reply

Your email address will not be published. Required fields are marked *