- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Conditional Constructs in Java
Chapter 9
Conditional Constructs in Java
Class 9 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Programs - Parcel Charge Calculation (Slab System)
Mayur Transport Company charges for parcels as per the following tariff:
|
Weight |
Charges |
|
Upto 10 Kg. |
Rs. 30 per Kg. |
|
For the next 20 Kg. |
Rs. 20 per Kg. |
|
Above 30 Kg. |
Rs. 15 per Kg. |
Write a program in Java to calculate the charge for a parcel, taking the weight of the parcel as an input.
import java.util.Scanner;
public class ParcelChargeCalculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter parcel weight (in kg): ");
double weight = sc.nextDouble();
double charge = 0;
if (weight <= 10) {
charge = weight * 30;
}
else if (weight <= 30) {
charge = (10 * 30) + ((weight - 10) * 20);
}
else {
charge = (10 * 30) + (20 * 20) + ((weight - 30) * 15);
}
System.out.println("\nTotal Parcel Charge = Rs. " + charge);
sc.close();
}
}
Output
Output 1 :
SAMPLE INPUT : Enter parcel weight (in kg): 8 SAMPLE OUTPUT : Total Parcel Charge = Rs. 240.0Output 2 :
SAMPLE INPUT : Enter parcel weight (in kg): 25 SAMPLE OUTPUT : Total Parcel Charge = Rs. 700.0Output 3 :
SAMPLE INPUT : Enter parcel weight (in kg): 40 SAMPLE OUTPUT : Total Parcel Charge = Rs. 1150.0
Explanation
1. Input
- The user enters the parcel weight in kilograms.
2. Slab-wise Calculation
- Up to 10 kg
Charge = Weight × 30
- 11 to 30 kg
Charge = (10 × 30) + (Remaining × 20)
- Above 30 kg
Charge = (10 × 30) + (20 × 20) + (Remaining × 15)
3. Output
- Displays the total parcel charge.
