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.
Here is my code thus far:
import java.util.Scanner;
public class investmentCalculator {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
double shares, purchase, selling;
int amountGain = 0, percentGain;
//User input for initial investment
System.out.print("Enter the number of shares: ");
double shares1 = input.nextDouble();
//User input for years invested
System.out.print("Enter the purchase price: ");
double purchase1 = input.nextDouble();
//User input for monthly interest rate
System.out.print("Enter the selling price: ");
double selling1 = input.nextDouble();
//Compute the future investment
double percentGain1 = (purchase1 - selling1) / (purchase1);
//Display result
System.out.println("Percent gain / loss: " + percentGain1);
System.out.println("Amount gain / loss: " + amountGain);
}
}
My Output is not correct though. I am thinking it has to do with my calculations. I am stuck and not sure what else I have to do to tweek it. Would someone be as kind to help me through this program? Many thanks in advance.
Here is my output:
Enter the number of shares: 1000
Enter the purchase price: 10.00
Enter the selling price: 20.00
Percent gain / loss: -1.0
Amount gain / loss: 0