Results 1 to 9 of 9
Like Tree2Likes
  • 1 Post By DarrylBurke
  • 1 Post By Fubarable

Thread: LongDistance Program Help

  1. #1
    Join Date
    Apr 2012
    Posts
    19
    Rep Power
    0

    Default 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 :)
    Last edited by B-52 Stratofortress; 04-23-2012 at 12:02 AM.

  2. #2
    shahrukh1 is offline Member
    Join Date
    Apr 2012
    Posts
    7
    Rep Power
    0

    Default 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
    Java Code:
    int days[] = new int[7];
    for(int i =0; i<7;i++)
    were every element of the array will be a day

  3. #3
    Join Date
    Apr 2012
    Posts
    19
    Rep Power
    0

    Default Re: LongDistance Program Help

    Quote Originally Posted by shahrukh1 View Post
    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
    Java 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?

  4. #4
    shahrukh1 is offline Member
    Join Date
    Apr 2012
    Posts
    7
    Rep Power
    0

    Default 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

  5. #5
    Join Date
    Apr 2012
    Posts
    19
    Rep Power
    0

    Default 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?

  6. #6
    shahrukh1 is offline Member
    Join Date
    Apr 2012
    Posts
    7
    Rep Power
    0

    Default 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

  7. #7
    Ksammie01 is offline Member
    Join Date
    Apr 2012
    Posts
    8
    Rep Power
    0

    Default 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
    LongDistance Program Help-untitled.png

    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..

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: LongDistance Program Help

    Quote Originally Posted by Ksammie01 View Post
    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 View Post
    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
    Ksammie01 likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  2. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  3. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •