DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

1. Registered User
Join Date
Apr 2005
Posts
2

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

Question:-

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.

Thnx.

Your help would be very appreciated.

2. Registered User
Join Date
Jan 2005
Posts
61
Not sure which but youre stuck on, so to start with, you need to create a method that accepts the parameters, something like this:
Code:
```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
•

 FAQ Latest Articles Java .NET XML Database Enterprise