I think I have a cluster of a mess here and was wondering if someone could help me in the right direction. I am trying to write a small program that will calculate the gain and/or loss of the sale of stock. The program will ask the user for the number of shares, the purchase price and the selling price. I am pretty sure that the errors is coming from my calculations in the program.
import java.util.Scanner; public class investmentCalculator { public static void main (String[] args) { Scanner input = new Scanner(System.in); //User input for number of shares System.out.print("Enter the number of shares: "); double shares = input.nextDouble(); //User input for purchase price System.out.print("Enter the purchase price: "); double purchase = input.nextDouble(); //User input for selling price System.out.print("Enter the selling price: "); double selling = input.nextDouble(); //Compute double originalCost = (shares * purchase); double earned = (shares * selling); double amountGainedOrLost = (earned - originalCost); double percentGain = amountGainedOrLost/(originalCost/1000); int earning = 0; int original = 0; System.out.println("Percent gain / loss: " + amountGainedOrLost + "%"); System.out.println("Amount gain / loss: $" + percentGain); } }
From the looks of my output, I am thinking I have zero '0' problems.
Enter the number of shares: 5000 Enter the purchase price: 400.00 Enter the selling price: 450.00 Percent gain / loss: 250000.0% Amount gain / loss: $125.0
Would someone please help me with this program. It seems like I have been working on it all day.