i will mark brailiest.....spammers and others stay away...only for educated ones...
Answers
Answer:
import java.util.*; //Scanner package name//
class ElectricityBill //class name//
{
String n; int phno; int u;
ElectricityBill() // initial instance variables of the value in a constructor//
{
n=" ";
phno=0;
u=0;
}
void accept(). //to accept the details given and to initialise the variables given//
{
Scanner Sc=new Scanner(System.in);
System.out.println("Enter the customer's name,phone number and units consumed:");
n=Sc.nextLine();
phno=SC.nextInt();
units=SC.nextInt();
}
double calculate(int unit) // to calculate the bill amount on the given condition//
{
double bill;
if(units less than 100)
{
bill= (double)units*1.50;
}
else if( units more than or equal to 100 and and units less than equal to 200)
bill=(double)100*1.50 + (units-100)*3;
}
else if(units more than or equal to 200 and and units less than equal to 400)
bill=(double)100*1.50+200*3+(units-400);
}
else
{
bill=(double)100*1.50+200*3+400*7.5;
}
return bill; //to return the variable bill after the given calculation is over//
}
void display () //to display the details given and the bill calculation amount in a separate calculate function//
{
System.out.println("Customer's name is="+n);
System.out.println("Phone number is="+phno);
System.out.println("Total units consumed are="+units);
System.out.println("The bill amount is="+bill);
System.out.println("The total bill calculation is="+calculate ());
}
void main() //to call the above methods by creating the object using construction methods//
{
ElectricityBill obj=new ElectricityBill()
obj.accept();
obj.display()
}
}
(NOTE:- "//" is used for comments or mnemonic codes for writing this program)
HOPE THIS HELPS.. ☺️