#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Unhappy Java StockProfit


    Hey anyone could help me I would be greatly appreciative. I am writing a program that asks me to write a method that accepts arguments the number of shares, the purchase price per share, the purchase commission paid, the sale price per share, and the sales commission paid. The method should return the profit or loss from the sale of stock. Demonstrate the method in a program that asks the user to enter the necessary data and displays the amount of the profit or loss. Here is what I have but it keeps saying I have an "else" without an "if" but I do have an "if". HELP lol
    import java.util.Scanner;


    public class StockProfit{



    public static void main(String[]args){

    Scanner keyboard = new Scanner(System.in);


    int Ns,Sp,Sc,Pp,Pc;

    int profit;

    System.out.println("Enter the number of shares");
    Ns=keyboard.nextInt();
    System.out.println("Enter the purchase price per share");
    Pp=keyboard.nextInt();
    System.out.println("Enter the purchase commission paid");
    Pc=keyboard.nextInt();
    System.out.println("Enter the sale price per share");
    Sp=keyboard.nextInt();
    System.out.println("Enter the sales commission paid");
    Sc=keyboard.nextInt();

    profit = ((Ns*Sp)-Sc)-((Ns*Pp)+Pc);

    if (profit > 0);

    {
    gain(profit);


    }
    else
    {

    loss(profit);
    }
    }

    public static void gain(int green){


    System.out.println("Your total profit was" +green);


    }
    public static void loss(int red){

    System.out.println("Your total loss was" +red);

    }

    }
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,614
    Rep Power
    1945
    remove the ; (semi-colon) from
    Code:
    if (profit > 0);

IMN logo majestic logo threadwatch logo seochat tools logo