ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2025 ICSE Computer Science Paper



Share with a Friend

Solved 2025 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Class & Object Based Program - Bank - ICSE 2025 Computer Science

Question 3
Define a class with the following specifications:
Class name: Bank
Member variables:
double p – stores the principal amount
double n – stores the time period in years
double r – stores the rate of interest
double a – stores the amount
Member methods:
void accept() – input values for p and n using Scanner class methods only.
void calculate() – calculate the amount based on the following conditions:

Time in (Years)

Rate %

Up to 1/2

9

> 1/2 to 1 year

10

> 1 to 3 years

11

> 3 years

12

void display() – displays the details in the given format:

Principal    Time    Rate    Amount

xxx          xxx     xxx     xxx

Write the main() method to create an object and call the above methods.

 

import java.util.Scanner; class Bank{ double p; double n; double r; double a; public void accept(){ Scanner in = new Scanner(System.in); System.out.print("Principal amount: "); p = Double.parseDouble(in.nextLine()); System.out.print("Time period in years: "); n = Double.parseDouble(in.nextLine()); } public void calculate(){ if(n <= 0.5) r = 9.0; else if(n <= 1.0) r = 10.0; else if(n <= 3.0) r = 11.0; else r = 12.0; a = p * Math.pow(1 + r / 100, n); } public void display(){ System.out.println("Principal\tTime\tRate\tAmount"); System.out.println(p + "\t\t" + n + "\t" + r + "\t" + a); } public static void main(String[] args) { Bank obj = new Bank(); obj.accept(); obj.calculate(); obj.display(); } }

Output

 
OUTPUT 1:
Principal amount: 10000
Time period in years: 2
Principal   Time    Rate    Amount
10000.0     2.0 11.0    12321.000000000002

OUTPUT 2:
Principal amount: 10000
Time period in years: 1.5
Principal   Time    Rate    Amount
10000.0     1.5 11.0    11694.575665666542