-2

I have a text file with the following two lines:

AAPL 101.50
MSFT 42.50

The text file will change with different tickers and prices so the text file is not constant. My question is, how can I pull just the ticker and then the price separate.

My program will have someone enter the ticker name and it should output the price. Furthermore, if someone enters a price and the price the user entered is less than a ticker price then it will show all the tickers with greater.

I am looking for info and some help on this since I'm new to Java. It is for a school assignment.

Thanks

  • http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html – Hans Petter Taugbøl Kragset Sep 16 '14 at 23:13
  • 1
    From the help center: "Questions asking for homework help must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it." You need to show us some effort to solve the problem, and give us a specific question or error you need help solving. If you're so stuck that you don't know where to start or don't have any code to share, you should start with some online tutorials or contact your instructor or a tutor. – skrrgwasme Sep 16 '14 at 23:24
  • Stack overflow is not a "teach me to program" site. – Lawrence Dol Sep 16 '14 at 23:26
  • I was able to figure it out. Thanks – chanoarg Sep 17 '14 at 14:19
  • By the way, I never asked anyone to solve it for me, I was simply asking for a little guidance to help me start. @lawrenceDol, don't worry I wont be asking any more question so you don't waste your time "teaching" since I'm sure your time is so valuable. – chanoarg Sep 17 '14 at 14:23
  • @chanoarg: Actually, you may want to consider that everyone on SO volunteers their time, and that many of us (myself included) are in fact professional programmers whose time ***is*** in fact valuable, both subjectively and objectively. The FAQ for SO makes it quite clear than SO is not intended to replace a classroom for learning the fundamentals of programming. And every question which ignores that guideline takes time away from other questions which are properly suited to the site and decreases the signal-noise ratio. – Lawrence Dol Sep 17 '14 at 19:36
  • Right on brotha! Keep it up! I will come back when I'm skilled enough to not bother you or waste your time :) @LawrenceDol – chanoarg Sep 18 '14 at 00:58

2 Answers2

1

Assuming you are getting a string like this from the file: "AAPL 101.50", it is pretty easy:

String[] values = input.split(" ");
String ticker = values[0];
String price = values[1]; //You'll need to convert that to a number yourself
Pokechu22
  • 4,984
  • 9
  • 37
  • 62
0

Rather than completely spoon feeding you the answer, you could look here, then another option could be to separate the input by space, i.e. if(" ") then assign value to element within an array.

Community
  • 1
  • 1
Paul Connolly
  • 94
  • 1
  • 2