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
- Item number for item which user wish to buy
- Quantity for the item entered above
When user enters above input, the code should check the stock
- 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
- घर बैठे ऑनलाइन करें हर महीने 60,000 रुपये तक कमायें 2022
- Top 5 Affiliate Marketing Program In India 2022
- Wishing Website क्या है और इससे पैसे कैसे कमाये? 2022
- एंड्राइड मोबाइल से पैसे कैसे कमाए 2022
- MS Word 2010 Download
- एंड्राइड मोबाइल से पैसे कैसे कमाए 2022
- Microsoft Powerpoint 2010 Free Download
- Download and Install IDM for PC in 2022
- Download & Install Wondershare Filmora X in 2022
- Office 2016 Pro Plus Free Download in 2022
- Adobe XD CC 2021 Free Download
- Adobe Premiere Pro 2022 Free Setup Download
- Unity 3D Pro Free Download in 2022
- TeamViewer Crack Version Download In Free 2022
- Digital Image Processing Multiple choice Questions unit wise 2021 AKTU
- How to Download and Install IDM for PC in 2022
- How to Download & Install Wondershare Filmora X in 2022
- Airlines Reservation System Java Project with Source Code
- All Unit MCQ’s of Data Compression AKTU Exam 2021
- HOW TO FIXED PROBLEM: Windows Update service missing (not listed) in
Also Read:
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