Q1)A mail-order house sells five products whose
retail prices are as follows : Product 1 : Rs. 199.90 , Product 2 : Rs. 200.20
, Product 3 : Rs. 63.87 , Product 4 : Rs. 145.50 and Product 5 : Rs. 540.49 . Write
an application that reads a series of pairs of numbers as follows: a) Product number b) Quantity sold your
program use a switch statement to
determine the retail price for each product. It should calculate and display
the total retail value of all products sold
ANSWER:
import java.util.*;
public class product
{
public
static void main(String args[])
{
Scanner
scn = new Scanner(System.in);
int
pNo=0;
int
qSold=0;
double
retailAmount=0.0;
double
totalAmount=0.0;
int
choice=0;
while(true)
{
System.out.print("Enter
Product Number : ");
pNo=scn.nextInt();
System.out.print("Enter
Quantity Sold : ");
qSold=scn.nextInt();
switch(pNo)
{
case
1:
retailAmount=qSold*199.90;
break;
case
2:
retailAmount=qSold*200.20;
break;
case
3:
retailAmount=qSold*63.87;
break;
case
4:
retailAmount=qSold*145.50;
break;
case
5:
retailAmount=qSold*540.49;
break;
}
System.out.println("Retail
Amount = " + retailAmount + " Rs.");
totalAmount=totalAmount+retailAmount;
System.out.print("Continue
(1)Yes/(0)No : ");
choice=scn.nextInt();
if(choice==1)
continue;
else
break;
}
System.out.println("\nTotal
Amount = " + totalAmount + " Rs.");
}
}
switch case can be used for long and complex conditional statement
ReplyDelete