# LongDistance Program Help

• 04-22-2012, 11:23 PM
B-52 Stratofortress
LongDistance Program Help
Write a program that computers the cost of a long-distance call. The cost of the call is determined according to the following rate schedule:
a. Any call started between 8:00 AM or after 6:00 PM, Mon-Fri, is billed at a rate of \$0.40 per minute.
b. Any call starting before 8:00 AM or after 6:00 PM, Mon-Fri, is charged at a rate of \$0.25 per minute.
c. Any call started on a Sat or Sun is charged at a rate of \$0.15 per minute.

You have to enter the:
Start Day: which is from Monday to Friday
Start Hour
Start Minute
Number of minutes talking...

The outcome should be the cost of the long distance call.

So far I had only learned for loops, while loops, and a bit of recursion. The question is, do I need to set up several methods in order to do this? More importantly, how do you do a loop between the days of the week?

Edit: Guys, I have trouble of understanding English, so be patient please :)
• 04-22-2012, 11:54 PM
shahrukh1
Re: LongDistance Program Help
you could do this program easily with a whole bunch of if statements, fairly simple
to loop through the days of the week is simple as well
Code:

```int days[] = new int[7]; for(int i =0; i<7;i++)```
were every element of the array will be a day
• 04-23-2012, 12:01 AM
B-52 Stratofortress
Re: LongDistance Program Help
Quote:

Originally Posted by shahrukh1
you could do this program easily with a whole bunch of if statements, fairly simple
to loop through the days of the week is simple as well
Code:

```int days[] = new int[7]; for(int i =0; i<7;i++)```
were every element of the array will be a day

It's actually not that easy, because I just don't get how to get from day 1 to day 2.
What confuses me if how can I renew the statements, like if the call starts at Sunday 11:00 PM, and ends at 1:00 AM of the next Monday. It will cost "\$0.25 * 60 + \$0.15 * 60".

"were every element of the array will be a day "
What do you mean?
• 04-23-2012, 12:15 AM
shahrukh1
Re: LongDistance Program Help
well
lets say our array

days[0] can be monday
and it continues.

day[1] can be tuesday

day[2] can be thursday
• 04-23-2012, 12:19 AM
B-52 Stratofortress
Re: LongDistance Program Help
How do you do that in Java? I never learned that. Can I get an example of going from Sunday to Monday?
• 04-23-2012, 12:42 AM
shahrukh1
Re: LongDistance Program Help
i suggest you read this very simple yet thorough tutorial on arrays.
Java arrays and loops in my opinion are very useful, accounts for 70% of solutions to code
http://docs.oracle.com/javase/tutori...ts/arrays.html
• 04-23-2012, 07:12 AM
Ksammie01
Re: LongDistance Program Help
can't you incorporate a GUI, where the person who is going to calculate the cost, types day when the call was made and the duration of the call.
then you read such information from the textfields into variables, and then you display the answer after the calculation is done
Attachment 3624

then you declare the days as variables and then you give them values..of course monday to friday will have the same value...then fri and sat will also have the same value
i think this will save you a lot of time. if you want the code for the Gui design, i can give it to you..
• 04-23-2012, 09:13 AM
DarrylBurke
Re: LongDistance Program Help
Quote:

Originally Posted by Ksammie01
can't you incorporate a GUI ...

Silly suggestion for someone who's struggling to understand exactly how to create and iterate over an array.

Quote:

Originally Posted by Ksammie01
if you want the code for the Gui design, i can give it to you..

This is a forum; please don't try to make it a code factory. People come here to learn, not to be given code they don't understand, and which is well beyond their present level in Java.

db
• 05-26-2012, 05:59 AM
Fubarable
Re: LongDistance Program Help
Spam post removed. Thread locked.