Requirements:
-user must be able to enter the name of the stock
-user must enter the number of shares originally purchased
-user must enter the share price at time of purchase($)
-user must be enter sales commission(entered as a percentage, not a decimal) paid to the stock broker
-user must enter the number of shares subsequently sold(which is less than or equal to the number of shares purchased)
-user must enter the share price at the time of the sale($)
What the output must produce:
-name of stock
-number of shares originally purchased
-share price at the time of purchase($)
-total amount of money the user paid for the stock ($) [TOTAL_PURCHASE]
-amount of money user paid to the stock broker during the purchase($)[PURCHASE_FEE]
-number of shares subsequently sold (which is less than or equal to the number of shares purchased)
-the share price at the time of sale($)
-the total amount of money the user received for selling the stock ($)[TOTAL_FEE]
-amount of money user paid to the stock broker during the sale ($) [SALE_FEE]
-total profit/loss which is calculated as ($):
TOTAL_SALE-SALE_FEE-TOTAL_PURCHASE-PURCHASE_FEE
Here is what I have so far:
import java.text.NumberFormat;
import java.util.*;
/*
* This program will show how much profit (or loss) the user realized on a sale of some stock in a company.
* Author: Mike Korb
* October 8, 2012
*/
public class StockPortfolio
{
public static void main(String[] args)
{final double COMMISSION_RATE = 2.75; // 2.75% commission rate
int sharePrice,shareTime;
double TOTAL_PURCHASE, commission, totalCost, numShares,sharesSold,SALE_FEE,PURCHASE_FEE,TOTAL_SALE;
String stockName;
Scanner scan = new Scanner (System.in);
NumberFormat fmt1 = NumberFormat.getCurrencyInstance();
NumberFormat fmt2 = NumberFormat.getPercentInstance();
System.out.print ("Name of stock: ");
System.out.print ("Number of shares: ");
numShares = scan.nextDouble();
System.out.print ("Share price: ");
sharePrice = scan.nextInt();
System.out.print ("Sales commission: ");
commission = scan.nextDouble();
System.out.print ("Shares sold: ");
sharesSold = scan.nextDouble();
System.out.print ("Shares price at time of sale: ");
sharesSold = scan.nextDouble();
TOTAL_PURCHASE = numShares;
SALE_FEE= TOTAL_PURCHASE * COMMISSION_RATE;
totalCost = TOTAL_SALE-SALE_FEE-TOTAL_PURCHASE-PURCHASE_FEE;
// Print output with appropriate formatting
System.out.println ("Total Purchase: " + fmt1.format(TOTAL_PURCHASE));
System.out.println ("Commission rate: " + fmt1.format(commission) + " at "
+ fmt2.format(COMMISSION_RATE));
System.out.println ("Total: " + fmt1.format(totalCost));
}
}
*Edited: please
This post has been edited by pbl: 08 October 2012 - 01:25 PM
Reason for edit:: Fixed code tags

New Topic/Question
Reply



MultiQuote




|