Skip to content

Commit bebebac

Browse files
Stock Transaction
1 parent a072c92 commit bebebac

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Last month Joe purchased some stock in Acme Software, Inc. Here are the details of the purchase:
3+
4+
• The number of shares that Joe purchased was 1,000.
5+
• When Joe purchased the stock, he paid $32.87 per share.
6+
• Joe paid his stockbroker a commission that amounted to 2% of the amount he paid for the stock.
7+
8+
Two weeks later Joe sold the stock. Here are the details of the sale:
9+
10+
• The number of shares that Joe sold was 1,000.
11+
• He sold the stock for $33.92 per share.
12+
• He paid his stockbroker another commission that amounted to 2% of the amount he received for the stock.
13+
14+
Write a program that displays the following information:
15+
• The amount of money Joe paid for the stock.
16+
• The amount of commission Joe paid his broker when he bought the stock.
17+
• The amount that Joe sold the stock for.
18+
• The amount of commission Joe paid his broker when he sold the stock.
19+
• Display the amount of profit that Joe made after selling his stock and paying the two commissions to his broker.
20+
(If the amount of profit that your program displays is a negative number, then Joe lost money on the transaction.)
21+
*/
22+
23+
package com.challenges;
24+
25+
public class StockTransaction {
26+
public static void main(String [] args) {
27+
28+
// Declare Variables
29+
30+
final int NO_OF_STOCKS = 1000;
31+
final double COST_PRICE = 32.87;
32+
final double COMMISSION_PERCENTAGE = 0.02;
33+
final double SELLING_PRICE = 33.92;
34+
double amtPaid;
35+
double buyingCommission;
36+
double amtReceived;
37+
double sellingCommission;
38+
double profit;
39+
40+
amtPaid = NO_OF_STOCKS * COST_PRICE;
41+
buyingCommission = amtPaid * COMMISSION_PERCENTAGE;
42+
amtReceived = NO_OF_STOCKS * SELLING_PRICE;
43+
sellingCommission = amtReceived * COMMISSION_PERCENTAGE;
44+
profit = (amtReceived - sellingCommission) - (amtPaid + buyingCommission);
45+
46+
System.out.println("Total Amount Paid by Joe: " + amtPaid);
47+
System.out.println("Total commission paid while buying: " + buyingCommission);
48+
System.out.println("Total Amount Received by Joe: " + amtReceived);
49+
System.out.println("Total commission paid while selling: " + sellingCommission);
50+
System.out.println("Total profit Joe made: " + profit);
51+
System.out.println("*If the amount of profit is negative, then Joe lost money on the transaction.");
52+
}
53+
}

0 commit comments

Comments
 (0)