You need to press A store has different categories of products in stock shown below. Item Number= [101, 102, 103, 104] Item Name= [Milk, Cheese, GK101.60 , Bread] Price= [42, 50, 500, 40] Stock= [10, 20, 15, 16] 4389 When user give input with 2 values as - 1. Item number for item which user wish to buy
input :
(item no) 101
(quantity)1
output :
total price 42
available quantity is : 9
answer in java :
import java.util.Scanner;
import java.io.*;
import java.lang.reflect.Array;
class Tcs {
public static void main(String[] args) {
int aqty=0;
int a,b,tot;
int it_no[]={101,102,103,104};
int qty[]={10,20,15,16};
int price[]={42,50,500,40};
System.out.print(" AVILABLE ITEMS,QTY,PRICE:\n"); for(int i=0;i<4;i++){
System.out.print("\t" + it_no[i] );
System.out.print("\t" + qty[i] );
System.out.print("\t" + price[i] + "\n");
} while(true) {
Scanner scan = new Scanner(System.in); System.out.print("\n\n\n========MENU=========\n"); System.out.print("DO YOU WANT SHOP NOW?\n"); System.out.print("1.yes \n 2.no");
System.out.print("\n enter your choice:");
int ch = scan.nextInt(); switch(ch) {
case 1: System.out.print("\n Enter item no:");
int tn = scan.nextInt();
System.out.print("Enter qty:");
int qt = scan.nextInt(); for(int i=0;i<4;i++)
if(it_no[i] == tn) {
b=qty[i]; if(b==0 || qt>b || qt==0 ) { System.out.print("NOT AVILABLE"); }
else {
a=price[i]; aqty=b-qt; tot= a * qt; System.out.print("total price is :" + tot); System.out.print("\n avilable qty is :" + aqty);
qty[i]=aqty; } }
break;
case 2: System.out.print("AFTER AVILABLE ITEMS,QTY,PRICE:\n");
for(int i=0;i<4;i++){ System.out.print("\t" + it_no[i] ); System.out.print("\t" + qty[i] ); System.out.print("\t" + price[i] + "\n"); }
System.exit(0);
break;
default:System.out.print("AFTER AVILABLE ITEMS,QTY,PRICE:\n"); for(int i=0;i<4;i++){ System.out.print("\t" + it_no[i] ); System.out.print("\t" + qty[i] ); System.out.print("\t" + price[i] + "\n"); } System.exit(0); break;
} }} }
Answers
Answer:
Scanner scan = new Scanner(System.in); System.out.print("\n\n\n========MENU=========\n"); System.out.print("DO YOU WANT SHOP NOW?\n"); System.out.print("1.yes \n 2.no");
System.out.print("\n enter your choice:");
int ch = scan.nextInt(); switch(ch) {
case 1: System.out.print("\n Enter item no:");
int tn = scan.nextInt();
System.out.print("Enter qty:");
int qt = scan.nextInt(); for(int i=0;i<4;i++)
if(it_no[i] == tn) {
b=qty[i]; if(b==0 || qt>b || qt==0 ) { System.out.print("NOT AVILABLE"); }
else {
a=price[i]; aqty=b-qt; tot= a * qt; System.out.print("total price is :" + tot); System.out.print("\n avilable qty is :" + aqty);
qty[i]=aqty; } }
break;
case 2: System.out.print("AFTER AVILABLE ITEMS,QTY,PRICE:\n");
for(int i=0;i<4;i++){ System.out.print("\t" + it_no[i] ); System.out.print("\t" + qty[i] ); System.out.print("\t" + price[i] + "\n"); }
System.exit(0);
break;
default:System.out.print("AFTER AVILABLE ITEMS,QTY,PRICE:\n"); for(int i=0;i<4;i++){ System.out.print("\t" + it_no[i] ); System.out.print("\t" + qty[i] ); System.out.print("\t" + price[i] + "\n"); } System.exit(0); break
Answer:- The program related to your question is written below. Given in question that you need to press a store has different categories of products in stock shown below:-
1. Item Number= [101, 102, 103, 104] Item Name= [Milk, Cheese, GK101.60, Bread]
2. Price= [42, 50, 500, 40] Stock= [10, 20, 15, 16]
When user give input with 2 values.
Scanner scan = new Scanner (System.in); System. out. print("\n\n\n========MENU=========\n");
System. out. print ("DO YOU WANT SHOP NOW \n");
System. out. print("1.yes \n 2.no");
System. out. print("\n enter your choice:");
int char = scan.nextInt(); switch(char)
{
case 1: System. out. print ("\n Enter item no:");
int Tn = scan.nextInt();
System. out. print("Enter qty:");
int qt = scan.nextInt(); for(int i=0;i<4;i++)
if(it is no[i] == Tn)
{
b=qty[i]; if(b==0 || qt>b || qt==0 )
{ System. out. print("NOT AVILABLE");
}
else {
a=price[i];
aq type=b-qt;
tot= a * qt;
System. out. print("total price is :" + tot);
System. out. print("\n available qty is :" + aqty);
qty[i]=aqty;
}
}
break;
case 2:
System. out. print("AFTER AVILABLE ITEMS,QTY,PRICE:\n");
for(int i=0;i<4;i++)
{
System. out. print("\t" + it is no[i] );
System. out. print("\t" + qty[i] );
System. out. print("\t" + price[i] + "\n");
}
System.exit(0);
break;
default: System. out. print("AFTER AVILABLE ITEMS, QTY, PRICE:\n");
for(int i=0;i<4;i++)
{
System. out. print("\t" + it is no[i] );
System. out. print("\t" + qty[i] );
System. out. print("\t" + price[i] + "\n");
}
System.exit(0);
break;
To know more about the given topic please go through the following
Link1:- https://brainly.in/question/46300195?
Link2:- https://brainly.in/question/46236791?
#SPJ3