ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2024 ICSE Computer Science Paper



Share with a Friend

Solved 2024 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Class & Object Based Program - Courier Service - ICSE 2024 Computer Science

Question 3

DTDC a courier company charges for the courier based on the weight of the parcel. Define a class with the following specifications:

class name: courier

Member variables:
name – name of the customer
weight – weight of the parcel in kilograms
address – address of the recipient
bill – amount to be paid
type – ‘D’ – domestic, ‘I’ international

Member methods:

void accept() – to accept the details using the methods of the Scanner class only.
void calculate() – to calculate the bill as per the following criteria:

Weight in Kgs

Rate per Kg

First 5 Kgs

Rs. 800

Next 5 Kgs

Rs. 700

Above 10 Kgs

Rs. 500

 

An additional amount of Rs. 1500 is charged if the type of the courier is I (International).
void print() – To print the details
void main() – to create an object of the class and invoke the methods.

 

import java.util.Scanner; class courier{ String name; double weight; String address; double bill; char type; public void accept(){ Scanner in = new Scanner(System.in); System.out.print("Customer name: "); name = in.nextLine(); System.out.print("Parcel weight in kg: "); weight = Double.parseDouble(in.nextLine()); System.out.print("Address: "); address = in.nextLine(); System.out.print("Parcel type: "); type = in.nextLine().charAt(0); } public void calculate(){ if(weight <= 5) bill = weight * 800; else if(weight <= 10) bill = 4000 + (weight - 5) * 700; else bill = 7500 + (weight - 10) * 500; if(type == 'I' || type == 'i') bill += 1500; } public void print(){ System.out.println("Customer name: " + name); System.out.println("Address: " + address); System.out.println("Parcel weight: " + weight); System.out.println("Parcel type: " + type); System.out.println("Bill = " + bill); } public static void main(String[] args){ courier obj = new courier(); obj.accept(); obj.calculate(); obj.print(); } }

Output

 
 OUTPUT 1: 
Customer name: Anand Rao
Parcel weight in kg: 10
Address: Bangalore
Parcel type: D
Customer name: Anand Rao
Address: Bangalore
Parcel weight: 10.0
Parcel type: D
Bill = 7500.0

 OUTPUT 2: 

Customer name: Ajay Singh
Parcel weight in kg: 12
Address: London
Parcel type: I
Customer name: Ajay Singh
Address: London
Parcel weight: 12.0
Parcel type: I
Bill = 10000.0