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; } }
Advertisement
Answer
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); } } }