QuestionAsk Questions?

View Answers

November 24, 2008 at 11:31 PM

Hi friend,

Code to solve the problem :

import java.io.*;

import java.text.*;

public class MeterReading {

public static double MyRound(int places, double value) {

return Math.round(value*Math.pow(10, places))/Math.pow(10, places);

}

public static void main(String [] args) throws IOException{

try{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter Current Reading");

int currentReading= Integer.parseInt(br.readLine());

System.out.println("Enter Previous Reading");

int previousReading = Integer.parseInt(br.readLine());

double result = 0;

double rate = 0;

int diffReading = currentReading - previousReading;

if(diffReading<=100)

{

rate = 1.25;

}

else if(diffReading>100 && diffReading<=250)

{

rate = 1.50;

}

else if(diffReading>250 && diffReading<=350)

{

rate = 1.80;

}

else if(diffReading>350)

{

rate = 2.20;

}

double bill = diffReading*rate;

System.out.println("Total Bill : " + MyRound(2,bill));

}

catch(Exception e){

System.out.println("Out of range!");

}

}

}

For more information on Java visit to :

http://www.roseindia.net/java/

Thanks

Vineet

Code to solve the problem :

import java.io.*;

import java.text.*;

public class MeterReading {

public static double MyRound(int places, double value) {

return Math.round(value*Math.pow(10, places))/Math.pow(10, places);

}

public static void main(String [] args) throws IOException{

try{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter Current Reading");

int currentReading= Integer.parseInt(br.readLine());

System.out.println("Enter Previous Reading");

int previousReading = Integer.parseInt(br.readLine());

double result = 0;

double rate = 0;

int diffReading = currentReading - previousReading;

if(diffReading<=100)

{

rate = 1.25;

}

else if(diffReading>100 && diffReading<=250)

{

rate = 1.50;

}

else if(diffReading>250 && diffReading<=350)

{

rate = 1.80;

}

else if(diffReading>350)

{

rate = 2.20;

}

double bill = diffReading*rate;

System.out.println("Total Bill : " + MyRound(2,bill));

}

catch(Exception e){

System.out.println("Out of range!");

}

}

}

For more information on Java visit to :

http://www.roseindia.net/java/

Thanks

Vineet

Related Tutorials/Questions & Answers: