Skip to content

Commit cc0daf9

Browse files
Stock Commission
1 parent 2bbc7ed commit cc0daf9

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Kathryn bought 600 shares of stock at a price of $21.77 per share.
3+
She must pay her stockbroker a 2 percent commission for the transaction.
4+
Write a program that calculates and displays the following:
5+
• The amount paid for the stock alone (without the commission)
6+
• The amount of the commission
7+
• The total amount paid (for the stock plus the commission)
8+
*/
9+
10+
package com.challenges;
11+
12+
public class StockCommission {
13+
public static void main(String [] args) {
14+
15+
// Declare Variables
16+
17+
int noOfShares = 600;
18+
final double STOCK_PRICE = 21.77;
19+
final double COMMISSION_PERCENT = 0.02;
20+
double totalStockAmt;
21+
double totalCommissionAmt;
22+
double totalAmt;
23+
24+
totalStockAmt = noOfShares * STOCK_PRICE;
25+
totalCommissionAmt = totalStockAmt * COMMISSION_PERCENT;
26+
totalAmt = totalStockAmt + totalCommissionAmt;
27+
28+
System.out.println("The amount paid for the stock (without commission: " + totalStockAmt);
29+
System.out.println("The amount of commission: " + totalCommissionAmt);
30+
System.out.println("Total Amount Paid: " + totalAmt);
31+
32+
}
33+
}

0 commit comments

Comments
 (0)