If else problem finding a phone bill using Java

A telephone company has the following billing system

  1. Calls up to 99 are free only 50 rupees phone rent.
  2. Calls from 100 to 199. 50 paise per call + 50 rupees rent.
    eg 102 calls will have 50 rupees rent + (102-99) * 0.5 rupees
    Bill = 50 + 3*0.50=51.50.
  3. Calls between 200 to 299 are at 75 paise per call.
    eg 201 calls will have 50 rupees rent + (199-99) * 0.50 (201-199) * 0.75
    50 rupee rent + charge of calls between 99  to 199 at 50 paise, then charge of calls above 199.
    Bill= 50 + 100*0.50 + 2*0.75 =50+50 + 1.50= 101.50
  4. Calls above 299 are 1 rupee per call.
    eg 303 calls will have 50 rupees rent + (199-99) * 0.50 (299-199) * 0.75 + (303-299) * 1.
    50 rupee rent + charge of calls between 99  to 199 at 50 paise, then charge of calls from 200 to 299 at 75 paise and 300+ at 1 rupee..
    Bill= 50 + 100*0.50 + 100*0.75 + 4*1 =50+50 + 75 + 4= 179

 

This is the code for the program:

public class PhoneBill {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println(“enter calls”);
int x=s.nextInt();
if(x<=99)
{
System.out.println(50);
}
else
if(x<199)
{
System.out.println(50+(x-99)*0.5);
}
else

if(x<=299)
{
System.out.println(100+(x-199)*.75);
}
else
{
System.out.println(175 + (x-299));
}
}
}

phone bill program

The output.

phone bill program output

 

Leave a Reply