3 Replies - 731 Views - Last Post: 08 October 2012 - 01:26 PM Rate Topic: -----

#1 mkorb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-October 12

Stock portfolio

Posted 06 October 2012 - 11:36 AM

Hey, I am having some trouble producing the output for this program, please be easy on me I'm a beginner. What the program has to do is to help the user figure out how much profit (or loss) the user received on a recent sale of some stock in a company.

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 :code:

This post has been edited by pbl: 08 October 2012 - 01:25 PM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Stock portfolio

#2 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: Stock portfolio

Posted 06 October 2012 - 11:44 AM

Please use code tags :)
Was This Post Helpful? 0
  • +
  • -

#3 Funkmachine  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 06-September 12

Re: Stock portfolio

Posted 06 October 2012 - 11:58 AM

OK, first of please use code tags in future.

Second, please clearly state what you want help with.

third, your program is ugly, but then again I suppose mine were when I started as well.

D, dont use import java.util.*; that is very bad practice, only import what you need, which by the look of your program is just Scanner.

Fifth, Please clearly state what you want help with, I see a problem and your solution, what is it your wondering about?
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Stock portfolio

Posted 08 October 2012 - 01:26 PM

And the question is ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1