#Calculating call charge

3 messages · Page 1 of 1 (latest)

heady eagle
#
A mobile company takes $125 every month for postpaid connection. For this, first 500 minutes are not charged. From 501 to 1000 minutes, every minute is charged $0.25 and from 1001 minute, every minute is charged $0.49. Write a java program to take total call duration as input (in minutes) and utputs total bill for that month.

This is the problem. Till now i have done this:

/*
    A mobile company takes $125 every month for postpaid connection. For this, first 500 minutes are not charged.
    From 501 to 1000 minutes, every minute is charged $0.25 and from 1001 minute, every minute is charged 
    $0.49. Write a java program to take total call duration as input (in minutes) and outputs total bill for that 
    month.
*/


import java.util.Scanner;

public class CallChargeCalculator {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        double bill = 125;
        System.out.print("Enter call duration in minutes: ");
        int minutes = input.nextInt();
        if (minutes <= 500) {
            System.out.println("Bill = " + bill);
        }
        else if (minutes > 500 && minutes <= 1000) {
            minutes -= 500;
            double currentBill = minutes * 0.25;
            bill += currentBill;
            System.out.println("Bill = " + bill);
        }
        else {
            minutes -= 500;
            double currentBill = minutes * 0.25;
            bill += currentBill;
            minutes -= 500; // so we minused 1000
            currentBill = minutes * 0.49;
            bill += currentBill;
            System.out.println("Bill = " + bill);
        }
    }
}

But the else block is not correct. Can anybody tell me what is the problem and how to solve it?

pallid forgeBOT
#

This post has been reserved for your question.

Hey @heady eagle! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.