DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2005

    Help with Methods

    I am a beginner in Java. I have been learning java by myself during the last few weeks and facing some difficulties with a question i got from a collegue of mine who did java at uni level. I don't know have to work with methods and she can't remember as well. Could some please help me out ??


    A telephone cost plan:

    Local calls are charged at $0.50 per minute(between 9a.m and 9pm). Long distance calls (> 200 miles) are charged at $1.10 per minute((between 9a.m and 9pm). From 9p.m to 9a.m,calls are charged at half the normal rate.

    I have to write a program which calculates the total cost of an arbitrary number of calls. For each call, the person using the phone needs to enter a time value (in 24hr mode), a distance (in miles), and a call length (in minutes). The program must then display the cost of that call and also adds the cost onto a cumulative total.

    When the phone user has no more calls to process, a time value of -999 instead of a legal time. When the program reads this sentinel value it displays the total cost of all the processed calls and ends.


    Your help would be very appreciated.

  2. #2
    Join Date
    Jan 2005
    Not sure which but youre stuck on, so to start with, you need to create a method that accepts the parameters, something like this:
    public double calculateCallCost(double time, long distance, int callLength) {
    //if else statments here
     return callCost;       
    //assuming user calls method something like this:
    //calculateCallCost(21.35, 300, 45);
    You'll need to intialize the variables first, eg double callCost, and then make sure that the results of your if else statements set that variable. That should get you started.
    Last edited by will808; 04-13-2005 at 06:51 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

By using this site, you agree to the Privacy Policy