Question

# Member Methods:(i) BookFair() – Default constructor to initialize data members.(ii) void Input() – To input and store the name and the price of the book.(iii) void calculate() – To calculate the price after discount. Discount is calculated based on the following criteria.

```				```
PRICE DISCOUNT
Less than or equal to Rs 1000:  2% of price
More than Rs 1000 and less than or equal to Rs 3000:  10% of price
More than Rs 3000:  15% of price
```
```

# Share code with your friends

Code

```				```
import java.util.Scanner;

public class BookFair
{
String Bname;
double price;

public BookFair()
{
Bname = "";
price = 0.0;
}

public void Input()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the book name: ");
Bname = sc.nextLine();
System.out.print("Enter the price: ");
price = sc.nextDouble();
}

public void calculate()
{
double discountPer = 0;
if (price <= 1000)
{
discountPer = 2;
}
else if (price > 1000 && price <= 3000)
{
discountPer = 10;
}
else if (price > 3000)
{
discountPer = 15;
}
price = price - (price * discountPer / 100);
}
public void display()
{
System.out.println("Name: " + Bname);
System.out.println("Price after discount: " + price);
}
public static void main(String[] args)
{
BookFair ob1 = new BookFair();
ob1.Input();
ob1.calculate();
ob1.display();
}
}

```
```

## Coding Store

Sale ### Mastering String

50
Sale 150
Sale 200
Sale ### Mastering Recursion

50
Sale ### Mastering Numbers

50
Sale ### Mastering Matrix

50
Sale ### Mastering Array

50
Sale ### ISC QUESTION PAPERS WITH SOLUTION(PROGRAMMING ONLY)

50
Sale 50