Page 294 - CA_Blue( J )_Class10
P. 294
class ElectricBill
{
String n;
int units;
double bill;
void accept()
{
Scanner sc= new Scanner(System.in);
System.out.print("Customer name: ");
n = sc.nextLine();
System.out.print("Units consumed: ");
units = sc.nextInt();
}
void calculate()
{
if(units <= 100)
bill = units * 2.0;
else if(units >= 200 && units <= 300)
bill = 200.0 + (units - 100) * 3.0;
else
{
bill = 800.0 + (units - 300) * 5.0;
bill = bill + 2.5 / 100 * bill;
}
}
void print()
{
System.out.println("Name of the customer: " + n);
System.out.println("Number of units consumed: " + units);
System.out.println("Bill amount: " + bill);
}
public static void main(String args[])
{
ElectricBill obj = new ElectricBill();
obj.accept();
obj.calculate();
obj.print();
}
}
15. Define a class named BookFair with the following description: [2016]
Instance variables/data members
String bName : stores the name of the book.
double price : stores the price of the book.
Member methods
void input () : to input and store the name and the price of the book.
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
void display() : to display the name and price of the book after discount.
292292 Touchpad Computer Applications-X

