- 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 8
Conditional Constructs in Java
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Program: Calculate the Parcel Charge based on the Weight Slabs
28. 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 ParcelCharge {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int weight;
double charge = 0;
System.out.print("Enter the weight of the parcel (in Kg): ");
weight = sc.nextInt();
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("Total Parcel Charge = Rs. " + charge);
}
}
Output
Sample Run Enter the weight of the parcel (in Kg): 35 Total Parcel Charge = Rs. 775.0
Calculation
- First 10 kg → 10 × 30 = 300
- Next 20 kg → 20 × 20 = 400
- Remaining 5 kg → 5 × 15 = 75
- Total = Rs. 775
✅ Explanation
- The program takes the parcel weight as input using Scanner.
- It uses an if–else ladder to apply slab-wise charges:
- First slab charged fully before moving to the next.
- The final charge is displayed in rupees.
