ICSE Computer Applications 2024 Boards Paper Solved Section B - Part 1

Ayush VanvaryAyush Vanvary
1 min read

Question 1. Description Based program -"courier charges"

                                        //instagram - @vanvaryclasses.in 
import java.util.*;
public class courier
{
    String name;
    int weight;
    String address;
    int bill;
    char type;

    void accept()
    {
        Scanner sc= new Scanner(System.in);
        System.out.println("Enter Name, Address, Weight, type(D or I)");
        name=sc.nextLine();
        address=sc.nextLine();
        weight=sc.nextInt();
        type=sc.next().charAt(0);
    }

    void calculate()
    {
        if(weight>0&&weight<=5)
            bill=weight*800;
        else if(weight>5&&weight<=10)
            bill=(5*800)+(weight-5)*700;
        else
            bill=(800*5)+(700*5)+(weight-10)*500; 

        int additional=(type=='I')?1500:0; // can also be done using if else
        bill=bill+additional;
    }
    void Print()
    {
        System.out.println("Name: "+name);
        System.out.println("bill: "+bill);
        System.out.println("type: "+(type=='D'?"Domestic":"International"));
        System.out.println("address: "+address);
    }
    public static void main(String args[])
    {
        courier ob = new courier();
        ob.accept();
        ob.calculate();
        ob.Print();
    }
}

Your can run above code in any java enabled ide and check for different test cases

if you have any questions connect- Ayush Vanvary

Follow @vanvaryclasses.in -Instagram

#vanvaryclasses.in

#icsejava #icsecomputers #javaprogramming

0
Subscribe to my newsletter

Read articles from Ayush Vanvary directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ayush Vanvary
Ayush Vanvary

Hello, I'm Ayush Vanvary. Skilled in Python Django and MySQL, I'm equally passionate about sharing my expertise as a tech educator. With experience as a Java tutor, I've honed both my coding prowess and teaching abilities. Additionally, I regularly contribute insights through straightforward, informative tech blogs, enriching readers and nurturing a vibrant community