Help with java prog...!

Reply

Join Date: Feb 2003
Posts: 35
Reputation: theQube is an unknown quantity at this point 
Solved Threads: 2
theQube theQube is offline Offline
Light Poster

Help with java prog...!

 
0
  #1
Jul 1st, 2003
Gah. I wrote all this code thnking that it would work properly, but it doesn't.

  1. //#13
  2. //Reads N days worth of stock prices,and spits out the highest increase.
  3. //Created 6/30/03, 8:38 PM
  4.  
  5. class StockWatcher
  6. {
  7. public static void main (String args [])
  8. {
  9. double today = 0.00; //price of stock today
  10. double yesterday; //price of stock yesterday
  11.  
  12. //EDIT "days" TO CAHNGE THE AMOUNT OF DAYS YOU WANT THE PROGRAM TO ANALYZE. Default is 10
  13. final int days = 10;
  14.  
  15. double everything = 0.00; // sum of everything
  16.  
  17. boolean goingup = true; //t/f value when price goes up. Original default at t
  18.  
  19. double highest = 0.00; //current highest value
  20.  
  21. double yhighest = 0.00; //highest from yesterday
  22.  
  23. double uberhighest = 0.00; //overall highest value
  24.  
  25. double minusdays = 0.00; //today - yesterday
  26.  
  27. System.out.println ("Welcome, day trader.");
  28.  
  29. System.out.println ("Enter values for " + days + " days worth of stock.");
  30.  
  31. for (int i = 1; i <= days; i++)
  32. {
  33. yesterday = today; //remember's the price from yesterday
  34.  
  35. today = SavitchIn.readDouble(); //collects today's value
  36.  
  37. everything += today; //changes value of price to keep updated
  38.  
  39. if (today < yesterday)
  40. {
  41. goingup = false;
  42. }
  43. if (today > yesterday)
  44. {
  45. minusdays = (today - yesterday);
  46. if (minusdays > highest)
  47. {
  48. uberhighest = minusdays;
  49. }
  50. }
  51. }
  52. System.out.println ("The highest difference between the stock values was $" + uberhighest + ".");
  53. }
  54. }

I need the program to find the largest increase in the 10 numbers inputted by the user, what the difference actually was, and when it happened (i.e., bet. day 4 and 5)

Any ideas? Its due TONIGHT!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC