Jump to content

Calculating Price with Command Line - Please Help!

- - - - -

  • Please log in to reply
3 replies to this topic

#1
rjdelight

rjdelight

    Newbie

  • Members
  • Pip
  • 4 posts
I'm trying to write a fairly simple program to calculate the price of some items. Basically, someone could type these items into the command line and it would be able to add them up and output the total. I seem to be going in circles and can't figure out this command line stuff/interacting with loops and so forth. I'm really buggard, so if someone could give me a hand I would really appreciate it.

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Well, first you should consider how you want to take in arguments, and what the expected user interface is. If you want to take in user input interactively on the command line, than you should use something like Scanner and give output using System.out.println(). If you want to take in arguments from a command line list like this:
C:\some\folder> java MyProgram 25.91 13.70 11.15

$50.76
The latter is easier to implement, since you don't need to take in interactive user input. Describe to me what the expected output for any given input is?
Wow I changed my sig!

#3
rjdelight

rjdelight

    Newbie

  • Members
  • Pip
  • 4 posts
I'm using Net beans and specify the arguments through that program. The output will be through Net beans too, I should have specified that sorry. I basically just want to have three services service a which will be $3, service b which will be $5 and service c which will be $10. I need the program to take the arguments, ie. someone types in service a and service c and it would output the total price as being $13 (3+10). So that in a nutshell is what I can't figure out.

#4
sourlemon

sourlemon

    Programmer

  • Members
  • PipPipPip
  • 99 posts
If there is no specific requirement on how you should take in the data, I would go with ZekeDragon's suggestion, make the user put it in when they start the program. So if would be something like this:

>java MyProgram a b c

That way you can avoid using loops. However, if this is an exercise to practice looping, then you need a value to specify that the user is done. For example, the user can type in a, b, or c. However, if the user types "done", you exit the loop, calculate the price and end the program. Does that make sense?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users