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 :)
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
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?
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
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?
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
1 Attachment(s)
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..
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
Re: LongDistance Program Help
Spam post removed. Thread locked.