grodek118

Stock Transaction Program

Sep 3rd, 2022
1,145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         double stock = 1000;
  9.         double boughtPerShare = 0.3287;
  10.         double commission = 0.02;
  11.         double boughtCommission;
  12.         double boughtPerStock;
  13.         double moneyBought;
  14.         double soldPerShare = 0.3392;
  15.         double soldCommission;
  16.         double soldPerStock;
  17.         double moneySold;
  18.         double profit;
  19.  
  20.  
  21.         boughtPerStock = (stock * boughtPerShare) * 1000; // money paid for the stock
  22.         System.out.println("The amount of money Joe paid for the stock: $" + boughtPerStock);
  23.         boughtCommission = boughtPerStock * commission; // 2% for the broker
  24.         System.out.println("The amount of commission Joe paid to broker when he bought the stock: $" + boughtCommission);
  25.         moneyBought = boughtPerStock - boughtCommission; // money paid - commission
  26.  
  27.         soldPerStock = (stock * soldPerShare) * 1000; // money earned from the stock
  28.         System.out.println("The amount that Joe sold the stock: $" + soldPerStock);
  29.         soldCommission = soldPerStock * commission; // 2% for the broker
  30.         System.out.println("The amount of commission Joe paid to broker when he sold the stock: $" + soldCommission);
  31.         moneySold = soldPerStock - soldCommission; // money earned - commission
  32.  
  33.         profit = moneySold - moneyBought; // difference between money earned and money bought
  34.         System.out.println(profit);
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment