aspose file tools*
The moose likes Beginning Java and the fly likes Help please !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help please !! " Watch "Help please !! " New topic
Author

Help please !!

D Imaz
Greenhorn

Joined: Apr 13, 2005
Posts: 5
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.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11406
    
  16

So what is your question?

The purpose here is not to hand you the answer to something that looks suspiciously like a homework assignment. If you have specific questions, or specific problems, ask away.

But posting a Generic "here's my assignment..." won't get you much help.

Anybody who "did java at uni level" and doesn't know how to work with methods should demand their tuition back


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
William A White
Ranch Hand

Joined: Jul 01, 2004
Posts: 35
Your question is too broad - you didn't identify where you are stuck.

For instance, do you have the knowledge to write a Hello World program in Java? Do you know how to read user input? Do you understand if-then logic?

It sounds like you might not know how to break up the code into appropriate methods. If that's the case, you should just write the whole program in the main method and then ask for help on redesigning it.
D Imaz
Greenhorn

Joined: Apr 13, 2005
Posts: 5
Fred if you don't wanna help. It's fine.
madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
Hi D,
i agree with one of the members saying " do you know how to write the hello world program"
Well D try to break your program into steps and then list out your steps so that we can identify where you are lost.

Give it a shot. The program sounds long but its quite simple.Thats why no direct answers are being posted.

Thanks


Money for nothing and Java for Free
SCJP, SCWCD
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11406
    
  16

You misunderstand. I (and many others here) DO want to help. But again, you have not asked a question. You've basically posted a homework assignment.

What have you done? What have you tried? How did it work differently than you expected?

Or, do you have Java installed? do you know how to compile a program? are you getting compile errors, and if so, post your code and the messages from the compiler.

You have to give me something to work with in order to help you.
kiennjal shah
Ranch Hand

Joined: Jun 17, 2004
Posts: 31
Before you even begin working on this problem, you must really get familiar with the basic syntax (conditional statements etc..) As stated earlier, Hello World! would be a good start.

Then, you should write pseudocode (or an algo) so that things are very clear when you actually begin writing your code.

For simplicity, you can just stuff all your code into the main method (though that is not a very good approach, but you can learn that as you proceed).

After that if you are stuck anywhere you can always post your questions here.

Hope this gets you started

-Kiennjal
D Imaz
Greenhorn

Joined: Apr 13, 2005
Posts: 5
I know how to write basic programs like the Hello World one but when it comes to methods i cant do anything.

what i know:

public class ....
{
public static void main(String[] args)
{
System.out.print("Hello World").

That's all i know and why i sollicited ur help as i badly wanna learn programming in java
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1010
    
    3
Originally posted by D Imaz:
I know how to write basic programs like the Hello World one but when it comes to methods i cant do anything.

...yet.
That's all i know and why i sollicited ur help as i badly wanna learn programming in java


Good. So you know the basic syntax for a program and how to compile and run it.

If you ask me, the next building block would be figuring out how to get the input for your program. Could you write a program that merely prints out what the user types in, one line at a time?

Ryan
D Imaz
Greenhorn

Joined: Apr 13, 2005
Posts: 5
no
Matt Fielder
Ranch Hand

Joined: Oct 27, 2004
Posts: 158
Put something together.
Even if it is completely wrong, just try.
The people in these forums are incredibly helpful.
You will get guidance if you put the effort in first.

EDIT:
Oh, and I forgot. Try making a subject that matches your problem so it can be searched later and be help to someone with the same issue.
[ April 13, 2005: Message edited by: Matt Fielder ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11406
    
  16

Believe it or not, you DO know how to write methods. main is a method. it takes a parameter (a String array) that we named 'args'. it's public, so anybody can call it. it's static, so it can be called without any object being created, and it doesn't return anything (void).

so you know a lot more than you thought.

Ryan is giving you good advice. Don't start off too big. just try and get some input from the user, and echo it back out. Get that to compile, run, and work correctly before the next step. it can probably be done in about 3 lines inside your main method. Heck, you may even want to start with a program that does nothing more than prompts the user for input and then exits. i.e. it doesn't actually GET the input, you just display what the prompt should be.

do you have a good book on Java? i'd reccomend the "head first Java" book by the JavaRanch's very own Kathy Sierra and Burt Bates. Also, you should become familiar with the API, found here. It can look a little daunting at first, but it really is vital. i refer to it almost every day. it tells you all about the java classes that already exist, and everything you can do with them. Things like Strings and Integers.
Jeff Jetton
Ranch Hand

Joined: Mar 29, 2005
Posts: 71
Originally posted by D Imaz:
no


Like the rest of the posters here, I'd suggest that you get a handle on these fundamentals first. You need to know how to play a C-major scale before you jump into playing a Beethoven sonata.

How are you going about teaching yourself? Are you following some online tutorials? Which ones? Have you bought a book (or two)? What books?

Whatever materials you're using, they should cover how to assign a value to a variable, and how to print that variable out. They should also cover how to read user input into a variable. If the materials you've chosen skip over this stuff, or address it in a way that's not clear, it might be time to pick some different materials. We'd be glad to offer recommendations.

And, by the way, the reason we're not just posting the code to solve your problem is because we do want to help. Guiding someone through the steps required to figure something out for themselves is the best way to do that.

- Jeff
D Imaz
Greenhorn

Joined: Apr 13, 2005
Posts: 5
Thank for your help !
Gjorgi Var
Ranch Hand

Joined: Feb 24, 2004
Posts: 85
Hola D,
Look, there are some steps that you have to take when approaching this and any future assignments that have nothing to do with synthax and everything to do with design... Do you think profi programmers spend all of their time coding? Most of the time is spent on design...
One simple and very helpfull technique is to identify the verbs and nouns in the problem description. Generally, nouns will be your classes and verbs will be the methods...
Good luck on your Java journey, hope you have a lot of fun...
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
Here's a very simple HelloWorld program to get you started. See if you can figure out the flow and what everything does. From there maybe you'll have specific questions.


[ April 13, 2005: Message edited by: Hentay Duke ]
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
This sounds like a job for The Java Tutorial.

You can't write an effective program without knowing at least the fundamentals of the language you want to write it in. Sun's tutorial is clearly written and well-paced and will get you up and running very very quickly. In fact, I would wager that if you spent just one day diligently going through the First Cup of Java and the Learning the Java Language sections of the tutorial, you'd be able to make great progress. At that point, you'd have the ability to try some things, see if they work, and to ask focused, direct questions that we would all happily answer.

But, you must first apply yourself to gaining at least a fundamental understanding of Java.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help please !!