• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Help please !!

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fred if you don't wanna help. It's fine.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank for your help !
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Yeah, but is it art? What do you think tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic