This is my homework
I am tring to write method sell that allows some shares of the stock to be sold at a given price. The method takes two arguments: a number of shares as an int, and a price per share as a double. The method returns a boolean value to indicate whether the sale was successful. For example:
// myStock now has 30 shares at total cost $90.00
boolean success = myStock.sell(5, 4.00);
// sells 5 shares at $4.00 successfully
// myStock now has 25 shares at total cost $70.00
success = myStock.sell(2, 5.00);
// sells 2 shares at $5.00 successfully
// myStock now has 23 shares at total cost $60.00
My Code :
public static void buy(int numBuyShares, double priceBuyShares)
{
double tempTotalCost = ((double)numBuyShares * priceBuyShares);
totalShares += numBuyShares;
totalCost += priceBuyShares;
}
public static void sell(int numSellShares, double priceSellShares)
{
?????
}
1.) How do I use the previous buy shares and cost to minus the sell stock and price ?