Results 1 to 9 of 9
- 01-21-2015, 05:17 AM #1
Member
- Join Date
- Jun 2014
- Posts
- 89
- Rep Power
- 0
The difference from one equation is being added to the total of another
I am writing a program for finding the profit made after paying the broker. here is my code, I am wondering why
Java Code:paidBroker = commission + commissionAfterSale;
Java Code:noProfit = profit - paidBroker;
Here is my full program, you can find these lines of code on lines 64 and 70.
Java Code:import java.util.Scanner; public class StockTransaction { public static void main(String[] args) { // TODO Auto-generated method stub //Variable Declaration Section double amceStockPurchasePrice; //Price per Acme Stock int acmeStockPurchased; //Number of Acme Stock purchased double commissionRate; //Commission of total price paid to broker double acmeStockSoldPrice; //Price per Acme Stock sold double grossTotalPaid; //Gross Total paid for Acme Stock double grossTotalReceived; //Gross Total Received after selling Acme Stock double commission; //Price paid to broker double profit; //Profit made from selling stock double commissionAfterSale; //Price paid to broker after the Joe sold his Acme Stock double paidBroker; //Amount Joe paid his broker in total double noProfit; //Total Amount of money Joe has after he paid his broker //Variable Initialization Section //Keyboard Scanner keyboard = new Scanner(System.in); //Code Section + Output Section System.out.print("How much was each Acme Share? $"); amceStockPurchasePrice = keyboard.nextDouble(); System.out.print("How many shares did Joe purchase? "); acmeStockPurchased = keyboard.nextInt(); //Calculate Gross Total Paid grossTotalPaid = acmeStockPurchased * amceStockPurchasePrice; System.out.print("Joe paid $" + grossTotalPaid + " for " + acmeStockPurchased + " shares. "); System.out.print("\nWhat percentage was Joe's brokers commission? "); commissionRate = keyboard.nextDouble(); //Calculate Commission after Joe bought the stock commission = grossTotalPaid * commissionRate; System.out.print("Joe's broker was paid $" + commission); System.out.print("\nJoe decided to sell his stock, how much did he sell each share for? $"); acmeStockSoldPrice = keyboard.nextDouble(); System.out.print("How many shares did Joe sell? "); acmeStockPurchased = keyboard.nextInt(); //Calculate Gross Total Received after sales grossTotalReceived = acmeStockSoldPrice * acmeStockPurchased; System.out.print("Joe recieved $" + grossTotalReceived + " for selling all " + acmeStockPurchased + " shares."); //Calculate Commission after Joe sold the stock commissionAfterSale = grossTotalReceived * commissionRate; System.out.println("\nJoes broker was paid $" + commissionAfterSale + " after the sale."); //Calculate Profit Joe made from selling his stock profit = grossTotalReceived - grossTotalPaid - commission - commissionAfterSale; //Calculate Amount Spent by Joe from paying his broker paidBroker = commission + commissionAfterSale; System.out.print("Joe's broker was in total paid " + paidBroker); //Calculate total after Joe paid his broker noProfit = profit - paidBroker; if(profit > paidBroker) System.out.print("\nJoe recieved $" + profit + " in profit."); else if(profit == paidBroker) System.out.print("\nJoe made no profit."); else System.out.println("\nJoe lost $" + noProfit); } }
- 01-21-2015, 04:11 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: The difference from one equation is being added to the total of another
Look at lines 62, 65, and 70.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 01-21-2015, 08:49 PM #3
Member
- Join Date
- Jun 2014
- Posts
- 89
- Rep Power
- 0
- 01-21-2015, 09:18 PM #4
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: The difference from one equation is being added to the total of another
I thought you said that paidBroker is added to noProfit (first post). In any event, please provide the input values and the output values and point out what the output should actually be.
Thanks,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 01-21-2015, 10:47 PM #5
Member
- Join Date
- Jun 2014
- Posts
- 89
- Rep Power
- 0
Re: The difference from one equation is being added to the total of another
This is my output:
How much was each Acme Share? $32.87
How many shares did Joe purchase? 1000
Joe paid $32870.0 for 1000 shares.
What percentage was Joe's brokers commission? .02
Joe's broker was paid $657.4
Joe decided to sell his stock, how much did he sell each share for? $33.92
How many shares did Joe sell? 1000
Joe recieved $33920.0 for selling all 1000 shares.
Joes broker was paid $678.4 after the sale.
Joe's broker was in total paid 1335.8
Joe lost $-1621.6
Joe's profit is $1050, he paid his broker $1335.8, this means he lost $285.8. Instead its added the 285.5 to the 1335.8 which gives me 1621.6.Last edited by sithclone3; 01-21-2015 at 10:50 PM.
- 01-21-2015, 10:58 PM #6
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: The difference from one equation is being added to the total of another
In line 62 you subtract the broker's fees to get the net profit. But in line 70 you subtract them out yet again. I haven't tested this, but that looks like a problem.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 01-22-2015, 12:23 AM #7
Member
- Join Date
- Jun 2014
- Posts
- 89
- Rep Power
- 0
- 01-22-2015, 12:59 AM #8
- 01-22-2015, 10:17 AM #9
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Similar Threads
-
Help with Equation
By TJRedeemer in forum New To JavaReplies: 11Last Post: 09-28-2013, 01:10 AM -
Need Help With Equation in Java
By Alsark in forum New To JavaReplies: 4Last Post: 02-12-2013, 05:04 PM -
Help with equation
By _Jk_ in forum New To JavaReplies: 10Last Post: 03-17-2011, 09:15 PM -
equation
By bobo67 in forum New To JavaReplies: 5Last Post: 09-06-2010, 07:40 PM -
differential equation RK4
By arvindmer in forum New To JavaReplies: 3Last Post: 01-08-2009, 02:27 PM
Bookmarks