Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class EasyStockMoney
- {
- public static void main(String [] args)
- throws FileNotFoundException
- {
- //Prompts user for stock name and the curret price
- Scanner console = new Scanner(System.in);
- System.out.println("Input the name of the stock");
- String stock = console.nextLine();
- System.out.println("Input the current price of the stock");
- double stockprice = console.nextDouble();
- //Reads the StockPurchaseHistory file for the amount of shares bought in the specific stock
- Scanner file = new Scanner(new File("StockPurchaseHistory.txt"));
- int sharecount = 0;
- double totalcost = 0.0;
- while(file.hasNextLine())
- {
- String line = file.nextLine();
- Scanner linescan = new Scanner(line);
- String companystock = linescan.next();
- if(companystock == stock)
- {
- int companyshares = linescan.nextInt();
- sharecount = sharecount + companyshares;
- double sharecost = linescan.nextDouble();
- //tax 2%
- sharecost = sharecost + (sharecost*0.02);
- totalcost = totalcost + (companyshares * sharecost);
- }
- }
- //calculates the current value of the companies shares
- double CurrentMarketValue = currentvalue(stockprice, sharecount);
- //calculates the current profit yield from the stock and gives you the predetermined warnings
- double Profit = ProfitCalculation(CurrentMarketValue, totalcost);
- System.out.println("Current Share Profit is" + Profit);
- if(Profit > 0.0)
- {
- if(1.30*totalcost <= CurrentMarketValue)
- {
- System.out.println("Your stock value per share has increased pass the 30 percent marker.");
- System.out.println("Would you like to sell it?");
- }
- else if(1.60*totalcost <= CurrentMarketValue)
- {
- System.out.println("Your stock value per share has increased pass the 60 percent marker.");
- System.out.println("Would you like to sell it?");
- }
- }
- if(Profit < 0.0)
- {
- if(.70*totalcost >= CurrentMarketValue)
- {
- System.out.println("!WARNING! YOUR STOCK VALUE HAS DECREASED PASS THE 30 PERCENT MARKER");
- }
- else if(.40*totalcost >= CurrentMarketValue)
- {
- System.out.println("!WARNING! YOUR STOCK VALUE HAS DECREASED PASS THE 60 PERCENT MARKER");
- }
- }
- }
- // method for calulating current market value of your stock in the specified company
- public static double currentvalue(double stockprice, int sharecount)
- {
- double CurrentValue = stockprice*sharecount;
- return CurrentValue;
- }
- //calculates the total profit yieled from said stock
- public static double ProfitCalculation(double CurrentMarketValue, double totalcost)
- {
- double Profit = CurrentMarketValue - totalcost;
- return Profit;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment