Professional Documents
Culture Documents
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
More than Rs 1000 and less than or equal to Rs 3000 10% of price
void display( ) - To display the name and price of the book after discount.
Write a main method to create an object of the class and call the above member methods.
Solution
import java.util.*;
class Bookfair
String Bname;
double price;
double discount;
double paid;
{
Scanner object= new Scanner(System.in);
Bname= object.next();
price= object.nextDouble();
if(price<=1000)
discount=(2*price)/100;
else if(price>1000&&price<=3000)
discount=(10*price)/100;
else
discount=(15*price)/100;
paid=price-discount;
obj.input();
obj.calculate();
obj.display();
Assignment 8
Define a class ElectricBill With the following specifications:
class : ElectricBill
Member methods:
void accept( ) – to accept the name of the customer and number of units consumed.
Write a main method to create an object of the class and call the above member methods.
Solution
import java.util.*;
class ElectricBill
String n;
int units;
double bill,surcharge;
n= object.next();
units= object.nextInt();
if(units<=100)
bill=(2*units);
else if(units>100&&units<=300)
bill=(2*100)+(3*(units-100));
else
bill= (2*100)+(3*200)+(5*(units-300));
surcharge=(bill*2.5)/100;
bill=bill+surcharge;
obj.accept();
obj.calculate();
obj.print();