Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I count the amount of extra numbers are given over a base value?

There is a base price and its only applicable when hrs = 50 and ppl = 30. I need to make it so that for each extra hrs or ppl it will charge an additional rate on top of the base rate. I am not sure how to make a piece of code that counts the extra hrs and ppl.

    public static void streamingCost(int hrs, int ppl, double base, double addRate) {
        hrs = 50;
        ppl = 33;

        base = 25;
        addRate = 2;

        if (hrs == 50 || ppl == 30) {
            double tot = base;
        }
    }

Also if my question was improper or you would like to down vote it, please tell me my mistake in the comments.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here all you need to do is calculate the extra charge. For each additional hour when ppl = 30, you need to calculate how many extra hours to finalise a total. Alternatively, for each additional person when hrs = 50, you need to calculate how many extra people there are to finalise a total.

This would be your code:

public static void streamingCost(int hrs, int ppl, double base, double addRate) {
        hrs = 50;
        ppl = 33;

        base = 25;
        addRate = 2;

        if (hrs == 50 || ppl == 30) {
            if (hrs > 50) {
                int temp = hrs - 50;
                double tot = base + (temp*addRate);
            }
            else if (ppl > 30) {
                int temp = ppl - 30;
                double tot = base + (temp*addRate);
            }
        }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading