Programming
Programming
Exercise
A mail-order house sells five products whose retail prices are as follows: Product 1 = RM2.98;
product 2 = RM4.50; product 3 = RM9.98; product 4 = 4.49 and product 5 = RM6.87. Draw a
flowchart and write a program that reads:
1. product number
2. quantity sold
Answer :
PAC
IPO
False
Price=RM
2.98
Price=RM False
True 4.50
False
True Price=RM
Product 1 9.98
Product 2 False
Price=RM
True
4.49
Product 3
True Price=RM
6.87
Product 4
True
Product 5
Pseudocode
Algorithm
Start
Case 1 :
Read quantity
Read quantity
Case 3 :
Read quantity
Case 4 :
Read quantity
Case 5 :
Read quantity
Total price=total price 1+ total price 2+ total price 3+ total price 4+ total price 5
End
Javacode
import java.util.Scanner;
double total=0.0;
boolean done=false;
double price=0;
switch (product){
case 1 :
price = 2.98;
break;
case 2 :
price = 4.50;
break;
case 3 :
price = 9.98;
break;
case 4 :
price = 4.49;
break;
case 5 :
price = 6.87;
break;
default :
done=true;
int quantity = 0;
if (!done){