0
import java.util.Scanner;

public class waterbill8
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);



double value1 = 5.00;
double value2 = 0.82;
double value3 = 0.65;
double value4 = 0.42;
double value5 = 15.00;
double value6 = 1.47;
String read1 = null;
char I, R;
int num1, num2, num3, num4, num5, num6;


System.out.println("*******************************************************************************");
System.out.println("This program will calculate the water bill for Residential or Industrial usage.");
System.out.println("*******************************************************************************");

double[] customer = new double[5];
for (int counter=0; counter < 5; counter++){


System.out.println("Please select I=Industrial or R=Residential");


System.out.print("Please select your choice, then hit enter=");
read1 = reader.next();


      if("R".equals(read1))
     {

    System.out.print("Input a past meter reading(m3), then hit enter=");
    num1 = reader.nextInt();

    System.out.print("Input a current meter reading(m3), then hit enter=");
    num2 = reader.nextInt();

    System.out.printf("Your usage of water is (m3): %d\n", (num2 - num1));
    num3 = num2 - num1;


        if ( num3 == 0)
        {
        value1 = 5.00;
        System.out.println("\nThe water bill is $" +value1);
        System.out.println();
        }
        else if (num3>=1 && num3<=15)
        {
        value2 = num3 * 0.82;
        System.out.printf("\nThe water bill is " +value2);
        System.out.println();
        }
        else if (num3>=15.1 && num3<=40)
        {
        value3 = num3 * 0.65;
        System.out.printf("\nThe water bill is " +value3);
        System.out.println();
        }
        else if(num3>=40.1)
        {
        value4 = num3 * 0.42;
        System.out.printf("\nThe water bill is " +value4);
        System.out.println();
        }       
    }

    else if ("I".equals(read1))
        {
    System.out.print("Input a past meter reading(m3), then hit enter=");
    num4 = reader.nextInt();

    System.out.print("Input a current meter reading(m3), then hit enter=");
    num5 = reader.nextInt();

    System.out.printf("Your usage of water is (m3): %d\n", (num5 - num4));
    num6 = num5 - num4;


        if ( num6 == 0)
        {
        value5 = 15.00;
        System.out.println("\nThe water bill is " +value5);
        System.out.println();
        }
        else if (num6>=1)
        {
        value6 = num6 * 1.47;
        System.out.printf("\nThe water bill is " +value6);
        System.out.println();
        }
}       
}

}
}

can someone help me with this ? im kind a new with java..thanks all

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by hszforu
0

When you want to print values using System.out.printf(), you need to use format specifiers.

change line 59 to

System.out.printf("\nThe water bill is %f ",value2);

Similarly change line 65 ,71 and 97.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.