Write a program in java to generate electricity bill on the following : - Java Programs
0Rani Singh
Write a program to generate electricity bill on the following:
unit <= 100 -₹5/unit
next 50 units -₹7
unit > 150 -₹8/unit
import java.util.Scanner;
public class bill
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the units consumed");
int u=sc.nextInt();
double amt=0.0;
if(u<=100)
amt=u*5;
else if(u>100 || u<=150)
amt=u*7;
else if (u<150)
amt=u*8;
{
System.out.println("Units Consumed="+u);
System.out.println("Bill Amount="+amt);
}
}
}
These are the terms used in this program which can be read by anyone like those who are intrested in java or programming , or a beginner in programming or in java , or a student ,etc . I recommend everyone to read this and get full control on programming.
Terms Used:
Import Statement : Import assertion or statement in Java is beneficial to take a category or all instructions seen for a software targeted below a package, with the assist of a unmarried assertion. It is quite useful because the programmer do now no longer require to write down the complete elegance definition. Hence, it improves the clarity of the software.
util : Package java. util. Contains the collections framework, a few internationalization aid classes, a provider loader, properties, random quantity generation, string parsing and scanning classes, base64 encoding and decoding, a chunk array, and numerous miscellaneous software classes.
Scanner class : The Scanner elegance or class is used to get user input, and it's far located within inside the java.util package. To use the Scanner elegance, create an item of the elegance and use any of the to be had strategies located within inside the Scanner elegance documentation.
public : Public is a Java key-word which broadcasts a member`s get right of entry to as public. Public individuals are seen to all different lessons. This approach that another elegance can get right of entry to a public area or method. Further, different lessons can adjust public fields until the sphere is said as final .
static : The static key-word is a non-get admission to modifier used for strategies and attributes. Static strategies/attributes may be accessed with out developing an item of a class
void : The void key-word specifies that a way need to now no longer have a go back value.
main : It is the call of the Java predominant method. It is the identifier that the JVM appears for because the place to begin of the java program. It`s not a keyword.
int : Int: By default, the int statistics kind is a 32-bit signed two`s supplement integer, which has a minimal cost of -231 and a most cost of 231-1.
System.out.println : To outline System. out. println() in Java, it's far a easy assertion that prints any argument you byskip and provides a brand new line after it. println() is liable for printing the argument and printing a brand new line. System.out refers to the usual output stream.
String args [] or String [] args : String[] args manner an array of collection of characters (Strings) which might be handed to the "main" function. This occurs whilst a application is executed. Example while you execute a Java application thru the command line: java MyProgram This is only a test. Therefore, the array will store: ["This", "is", "just", "a", "test"].
if : Thee Java if assertion or statement is the maximum easy decision-making assertion. It is used to determine whether or not a positive assertion or block of statements may be performed or now no longer i.e if a positive circumstance is real then a block of assertion is performed in any other case now no longer.
if else : Use if to specify a block of code to be executed, if a targeted circumstance is true. Use else to specify a block of code to be executed, if the equal circumstance is false. Use else if to specify a brand new circumstance to test, if the primary circumstance is false.