Write a java program that computes of the long distance call. The following cost of the call is determined according to the following rate schedule.

a. Any call started between 8:00 am and 6:00pm Monday through Friday is billed of a rate of \$ 0.40 per minute.
b. Any call starting before 8:00 am after 6:00 pm Monday through Friday is charge at a rate of \$0.25 per minute.
c. Any call started on Saturday or Sunday is charge of a rate of \$ 0.15 per minute.

The input will consist of the day of the week, the time the call started, and the length of the call in minutes. The output will be the cost of the call. The time is to be inputted in 24-hour notation, so the time 1:30 pm is input as 13:30 pm.

The day of the week will be read as one of the following pairs of the character value, which are stored in two variables of the type char.

Mo, Tu, We, Th, Fr, Sa, Su.

Be sure to allow the user to use either uppercase or lowercase letter or combination of the two.

The number of minutes will be input as a whole number of minutes. Your program should include a loop that lets the user repeat this calculation. Program, produce a variant on this program that reads the information for all the phone calls in one week from a file and then writes a phone bill of call as well as the total bill for all the calls. List the phone call in the output file in the same order as they appear in the input file.

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Random_Integer

What have you done so far??

oh, that's a fun one.
I would scan it in as a string.
use String.charAt(index); to compare the individual characters.

First, see what day of the week it is, knowing the time does not change anything without the day of the week. Knowing the day eliminates at least one option.
I would just see if the day is Saturday or Sunday. If not, it is mon-fri.
You can do this by searching through the string for a 'sa', 'Sa', 'su', or
'Su'. Alternatively you can have the loop change all characters to lower
case while you search.

From there figure out the time check the numbers behind the ':' because the ones after do not matter from what I see. Then check the am, pm.

once you go through all the "if" statements and such you should have a rate per minute. simply multiply that by the length of the call. and that should be it.

I am kind of tired so this could be kind of jumbled.
But hope the idea helped you.

Or you could have the program sort out the scanned in string into separate strings and figure it out from there. It might be prettier that way.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.