100% found this document useful (1 vote)
352 views

Programming

The document describes a program to calculate the total price of products sold from a mail-order house. It provides the retail prices of 5 products and asks the user to input the product number and quantity sold. The program uses a switch statement to select the price based on the product number, then multiplies it by the quantity to calculate the total price for that product. It repeats this for all products and sums the total prices to display the final total. Pseudocode and Java code implementations of the program are provided.

Uploaded by

Heizlyn Amyneina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
352 views

Programming

The document describes a program to calculate the total price of products sold from a mail-order house. It provides the retail prices of 5 products and asks the user to input the product number and quantity sold. The program uses a switch statement to select the price based on the product number, then multiplies it by the quantity to calculate the total price for that product. It repeats this for all products and sums the total prices to display the final total. Pseudocode and Java code implementations of the program are provided.

Uploaded by

Heizlyn Amyneina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Name : Heizlyn Amyneina Binti Hamzah

Matric No. : 182401

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

Calculate the total price for the products sold.

Display the output.

Answer :

PAC

Data Processing Output


- Product number,price - Calculate total price for - Total price for products
of product number and products sold sold
quantity sold

IPO

Data Processing Method Output


- Product - Enter product - Total price
number number
- Price of - Enter quantity
product sold
- Quantity sold - Total
price=price of
product
number*quant
ity sold
- Print total
price
- End
Flowchart

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

Read product number

Case 1 :

Read quantity

Total price 1= price of product number 1*quantity sold


Case 2 :

Read quantity

Total price 2= price of product number 2*quantity sold

Case 3 :

Read quantity

Total price 3= price of product number 3*quantity sold

Case 4 :

Read quantity

Total price 4= price of product number 4*quantity sold

Case 5 :

Read quantity

Total price 5= price of product number 5*quantity sold

Total price=total price 1+ total price 2+ total price 3+ total price 4+ total price 5

Print total price

End
Javacode

import java.util.Scanner;

public class Retail {

public static void main(String[] args) {

double total=0.0;

Scanner input=new Scanner (System.in);

boolean done=false;

for (int i=0;i<5 && !done;i++){

System.out.println("Enter product number (1-5),or -1 to quit");

int product = input.nextInt();

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){

System.out.println("Enter number of quantities sold:");


quantity = input.nextInt();

total += price * quantity;

System.out.println("Total income :" + total);

// TODO code application logic here

You might also like