Write an application that computes the cost of a telephone call. The inputs

are the time the call was placed (this should be written as a 24-hour time, e.g.,

2149 for a call placed a 9:49p.m.), the duration of the call in minutes, and the

distance in miles of the destination of the call. The output is the cost of the

call. Cost is computed as follows:


²

Basic cost is $0.003 per minute per mile.


²

Calls placed between 8am and midnight (800 to 2400) are subject to a 20%


surcharge. (That is, basic cost is increased by 0.2.)


²

A tax of 6% is added to the cost.


The di±cult part of this project is computing the surcharge, if any. To help do


this, use the operation

Math.ceil(E), which returns the nearest integer value


that is not less than

E. For example, Math.ceil(0.2359 - 0.0759) equals 1.0,


but
Math.ceil(0.0630 - 0.0759) equals 0.0.


THIS is what i've done so far

public class telCost {
public static void main (String[] args) {
	int time = new Integer(args[0]).intValue();
	
	int calltime = new Integer(args[1]).intValue();
	
	double distance = new Double(args[2]).doubleValue();
	double price = distance* calltime * 0.0003;
	price = price  * (6/price);
	
	if (time > 800 && time < 2400 ) 
		System.out.println(price +0.2);
	else System.out.println(price);
   }
}

i cant understand the problem so farr , the surcharge and the use of math.ceil ???!

this looks and afwull lot like another thread you started.
what exactly is your question? what exactly ceil does, how you should fit it in your code or why you should do so?

you should better start easy, doing this step by step.
for instance, calculating the basic cost, without taking into consideration the special bonus.
when this works, add the functionality which checks for that percentage.

after that, add the rest of the steps gradually.

also, for a question: could you be a bit more specific than "i cant understand the problem so farr , the surcharge and the use of math.ceil ???! "?

ok .. so i've done the basic price which is

1 . Basic cost is $0.003 per minute per mile which i've done it this way

double price = distance* calltime * 0.0003;

right ?!


2. after this >> A tax of 6% is added to the cost

price = price  * (6/price);

I don't know if this is correct though !


3. next we have >> Calls placed between 8am and midnight (800 to 2400) are subject to a 20%surcharge. (That is, basic cost is increased by 0.2.)

if (time > 800 && time < 2400 ) 
		System.out.println(price +0.2);
	else System.out.println(price);

/ the input for time is for example 2149 for 21:49 /

here i don't understand increased means to price + 0.2 or price * 0.2 ??


4 .in the end I don't know how or where to use math.ceil :))

clear enough ? thank you for ur time !

1 . Basic cost is $0.003 per minute per mile which i've done it this way

double price = distance* calltime * 0.0003;

right ?!

looks to me like you have one 0 too much

2. after this >> A tax of 6% is added to the cost

price = price  * (6/price);

I don't know if this is correct though !

it's not.
to find 6% of a variable x:
(x/100) * 6

3. next we have >> Calls placed between 8am and midnight (800 to 2400) are subject to a 20%surcharge. (That is, basic cost is increased by 0.2.)

if (time > 800 && time < 2400 ) 
		System.out.println(price +0.2);
	else System.out.println(price);

/ the input for time is for example 2149 for 21:49 /

here i don't understand increased means to price + 0.2 or price * 0.2 ??

neither .. you need to add 20% of the current number. see my previous answer on how to find the percentage

4 .in the end I don't know how or where to use math.ceil :))
clear enough ? thank you for ur time !

how to use it? you've set examples in your description, so you do know how to use it (I assume). where to use it ... since you don't really specify that, I have no idea.

thank you very much .. I did it all but today they told me that I CAN'T USE IF STATEMENTS :(( .. any idea about writing this

Calls placed between 8am and midnight (800 to 2400) are subject to a 20%surcharge. (That is, basic cost is increased by 0.2.)

without IF STATEMENT ??

thank you

And why aren't you allowed?

well you could use a loop that only runs once

but that would be bad programming even it solves the problem but hey

neither of loops , while , switch (case) , if , else ,for .. none of thesee because the project is in the first chapter of the book :@

This seems a stupidly designed Java exercise to me - let's do some cunning logic but no if tests? - but hey ho.
There must be mathematical formulae (using the ceil function) that evaluate to 1 if a variable is larger/smaller than some reference variable, and zero otherwise.
So if formula1 is a purely mathematical function equivalent to
(var-800 > 0)?1:0;
and formula2 is a similar one equivalent to
(2400-var > 0)?1:0;
If you code those formulae then you can use it as in
price = price + price*0.2*formula1*formula2;

I can' think what those formulae are, but I'm sure they exist, and there are an awful lot of very smart people on DaniWeb...

commented: agree +6

I did it .. thank you very much the part with if could've been written like this

String price1 = time>=800&&time<=2400 ? Math.ceil(price + tax) + "" : Math.ceil(price)+ "";
System.out.print(price1);

It took me some time but I got it , this thread can be closed :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.