import java.util.*;
class BookFair
{
String Bname;
double price,amount;
BookFair()
{
Bname="";
price=0.0d;
amount=0.0;
}
void input()
{
Scanner sc=new Scanner (System.in);
System.out.print("Enter the Book name: ");
Bname=sc.nextLine();
System.out.print("Enter the Price of the Book : ");
price=sc.nextDouble();
}
void calculate()
{
if(price<=1000)
amount=price*2/100;
else if(price<=3000)
amount=price*10/100;
else
amount=price*15/100;
}
void display()
{
System.out.println("The Name of the Book is "+Bname);
System.out.println("The Price of the Book is "+price);
System.out.println("The Actual Amount to be paid is "+amount);
}
void main()
{
BookFair ob=new BookFair();
ob.input();
ob.calculate();
ob.display();
}
}
==================================================
import java.util.Scanner;
class ElectricityBill
{
String n;
int units;
double bill;
ElectricityBill()
{
n="";
units=0;
bill=0.0d;
}
void accept()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Name of the Customer:");
n = sc.next ();
System.out.print("Enter the Number of Units Consumed");
units = sc.nextInt();
}
void calculate()
{
if(units<=100)
bill = 10 * units;
else if(units<=200) //next 100 units
bill = 10 * 100 + (units - 100) * 15;
else if(units<=300) //next 100 units
bill = 10 * 100 + 100 * 15 + (units - 200) * 20;
else //above 300 units
{
bill = 10*100 + 100*15 + 100*20 + (units-300) * 25;
bill = bill + bill * 2.5 /100; //surcharge 2.5%
}
}
void display()
{
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()
{
ElectricityBill obj = new ElectricityBill();
obj.accept();
obj.calculate();
obj.display();
}
}