ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2024 ICSE Computer Science Specimen Paper



Share with a Friend

Solved 2024 ICSE Computer Science Specimen Paper

Class 10 - ICSE Computer Science Solved Specimen Papers

Class & Object Based Program - Eshop - ICSE 2024 Computer Science Specimen Paper

Question 3
Define a class called Eshop with the following specifications:

Class name: Eshop

Member variables:
String name: name of the item purchased
double price: price of the item purchased

Member methods:
void accept(): accept the name and the price of the item using the methods of Scanner class.
void calculate(): to calculate the net amount to be paid by a customer, based on the following criteria:

Price

Discount

1000 – 25000

5.0%

25001 – 57000

7.5%

57001 – 100000

10.0%

More than 100000

15.0%

 

void display(): to display the name of the item and the net amount to be paid.

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

 

import java.util.Scanner; class Eshop{ String name; double price; public void accept(){ Scanner in = new Scanner(System.in); System.out.print("Item: "); name = in.nextLine(); System.out.print("Price: "); price = Double.parseDouble(in.nextLine()); } public void calculate(){ double dp = 0.0; if(price >= 1000 && price <= 25000) dp = 5.0; else if(price > 25000 && price <= 57000) dp = 7.5; else if(price > 57000 && price <= 100000) dp = 10.0; else if(price > 100000) dp = 15.0; double discount = dp / 100 * price; price -= discount; } public void display(){ System.out.println("Item name: " + name); System.out.println("Net bill: " + price); } public static void main(String[] args){ Eshop obj = new Eshop(); obj.accept(); obj.calculate(); obj.display(); } }

Output

 
 OUTPUT 1: 
Item: Mobile Phone
Price: 35000
Item name: Mobile Phone
Net bill: 32375.0

 OUTPUT 2: 
Item: Laptop
Price: 65000
Item name: Laptop
Net bill: 58500.0