iTSCET

iT Portal

A java program to check Electricity consumption charge !!

import java.util.InputMismatchException;
import java.util.Scanner;

public class CurrentConsumption {
static double score;
public static void main(String[] args) {
CurrentConsumption d = new CurrentConsumption();
System.out.println(“Enter Your Consumption in Units: “);
Scanner Scan = new Scanner(System.in);
try{
score = Scan.nextDouble();
d.printGrade(score);
}catch (InputMismatchException e) {
System.out.println(“Enter valid Units !!”);
}
}

public void printGrade(double score) {

if (score <= 100) {
double A = score * 1.00;
System.out.println("your Consumption charge in Rs:" + A);
} else if (score <= 200) {
double B = score * 1.50;
System.out.println("your Consumption charge in Rs: " + B);
} else if (score <= 500) {
double C = score * 3.50;
System.out.println("your Consumption charge in Rs: " + C);
}else if (score > 500) {
double D = score * 5.75;
System.out.println(“your Consumption charge in Rs:” + D);
}
}
}

– codes by ashokkumar

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: