Define a class called with the following specifications:

ICSE Class 10 Computer Applications PYQ · 2024 Specimen · Section B

3Written · 2024 · Section B · 2024 Specimen

Define a class called 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:

PriceDiscount
1000 – 250005.0%
25001 – 570007.5 %
57001 – 10000010.0%
More than 10000015.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.

Show SolutionHide Solution↓
import java.util.Scanner;
public class Eshop
{
    private String name;
    private double price;
    private double disc;
    private double amount;

    public void accept() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter item name: ");
        name = in.nextLine();
        System.out.print("Enter price of item: ");
        price = in.nextDouble();
    }
    
    public void calculate() {
        double d = 0.0;
        
        if (price < 1000)
            d = 0.0;
        else if (price <= 25000)
            d = 5.0;
        else if (price <= 57000)
            d = 7.5;
        else if (price <= 100000)
            d = 10.0;
        else
            d = 15.0;
        
        disc = price * d / 100.0;
        amount = price - disc;
        
    }
    
    public void display() {
        System.out.println("Item Name: " + name);
        System.out.println("Net Amount: " + amount);
    }
    
    public static void main(String args[]) {
        Eshop obj = new Eshop();
        obj.accept();
        obj.calculate();
        obj.display();
    }
}
BlueJ output of Eshop.java
← Previous questionNext question →

Browse the free Computer Applications sample bank