willieshi232

Untitled

Jan 25th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class EasyStockMoney
  4. {
  5. public static void main(String [] args)
  6. throws FileNotFoundException
  7. {
  8.  
  9. //Prompts user for stock name and the curret price
  10. Scanner console = new Scanner(System.in);
  11. System.out.println("Input the name of the stock");
  12. String stock = console.nextLine();
  13. System.out.println("Input the current price of the stock");
  14. double stockprice = console.nextDouble();
  15.  
  16. //Reads the StockPurchaseHistory file for the amount of shares bought in the specific stock
  17. Scanner file = new Scanner(new File("StockPurchaseHistory.txt"));
  18. int sharecount = 0;
  19. double totalcost = 0.0;
  20. while(file.hasNextLine())
  21. {
  22. String line = file.nextLine();
  23. Scanner linescan = new Scanner(line);
  24. String companystock = linescan.next();
  25. if(companystock == stock)
  26. {
  27. int companyshares = linescan.nextInt();
  28. sharecount = sharecount + companyshares;
  29. double sharecost = linescan.nextDouble();
  30. //tax 2%
  31. sharecost = sharecost + (sharecost*0.02);
  32. totalcost = totalcost + (companyshares * sharecost);
  33. }
  34. }
  35.  
  36. //calculates the current value of the companies shares
  37. double CurrentMarketValue = currentvalue(stockprice, sharecount);
  38. //calculates the current profit yield from the stock and gives you the predetermined warnings
  39. double Profit = ProfitCalculation(CurrentMarketValue, totalcost);
  40. System.out.println("Current Share Profit is" + Profit);
  41. if(Profit > 0.0)
  42. {
  43. if(1.30*totalcost <= CurrentMarketValue)
  44. {
  45. System.out.println("Your stock value per share has increased pass the 30 percent marker.");
  46. System.out.println("Would you like to sell it?");
  47. }
  48. else if(1.60*totalcost <= CurrentMarketValue)
  49. {
  50. System.out.println("Your stock value per share has increased pass the 60 percent marker.");
  51. System.out.println("Would you like to sell it?");
  52. }
  53. }
  54. if(Profit < 0.0)
  55. {
  56. if(.70*totalcost >= CurrentMarketValue)
  57. {
  58. System.out.println("!WARNING! YOUR STOCK VALUE HAS DECREASED PASS THE 30 PERCENT MARKER");
  59. }
  60. else if(.40*totalcost >= CurrentMarketValue)
  61. {
  62. System.out.println("!WARNING! YOUR STOCK VALUE HAS DECREASED PASS THE 60 PERCENT MARKER");
  63. }
  64. }
  65. }
  66.  
  67. // method for calulating current market value of your stock in the specified company
  68. public static double currentvalue(double stockprice, int sharecount)
  69. {
  70. double CurrentValue = stockprice*sharecount;
  71. return CurrentValue;
  72. }
  73.  
  74. //calculates the total profit yieled from said stock
  75. public static double ProfitCalculation(double CurrentMarketValue, double totalcost)
  76. {
  77. double Profit = CurrentMarketValue - totalcost;
  78. return Profit;
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment