Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help with Stock Profit Program

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help with Stock Profit Program

    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
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with Stock Profit Program

    "else" without an "if"
    The problem is that the if statement ends at the ; The code following the ; is not part of the if statement.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    pherigo (March 30th, 2013)

  4. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help with Stock Profit Program

    So could I remove the ;?

    --- Update ---

    SOLVED

Similar Threads

  1. Mobile Applications Developer £40k + profit share - North Lancashire
    By john_sedgewick in forum Paid Java Projects
    Replies: 0
    Last Post: February 28th, 2013, 08:24 AM
  2. Need help with a beginning level stock program
    By laughingeyes18 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 30th, 2011, 10:31 PM
  3. stock charts...
    By theChameleon in forum Java Theory & Questions
    Replies: 1
    Last Post: February 24th, 2011, 05:11 AM