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 2 of 2

Thread: Need help with calculating stock code.

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with calculating stock code.

    /*This program was written by **** March 20, 2012 for CISM **** to show each person’s name, name of stock he or she purchased, the stock value, the amount of the stock commission, and the total amount paid for the stock.
    */
    import javax.swing.JOptionPane;
    import java.math.BigDecimal;
    import java.text.NumberFormat;
    import java.util.Locale;

    public class Stock
    {
    public static void main(String[] args)
    {
    //Declare variables
    int numberofShares = 0,priceperShare = 0,valueofShares=0;
    BigDecimal amount;
    double commission = 0.00, double totalStockcost = 0.00 double amtStockcommision = 0.00;
    //Ask for First and Last name
    String name = "";


    First name = JOptionPane.showInputDialog(
    null, "Please enter your first name: ");

    LastName = JOptionPane.showInputDialog(
    null, "Please enter your last name: "));



    //Create list string to call later
    String list =
    "1 for Apple \n"+
    "2 for Microsoft \n"+
    "3 for DELL \n";

    //Ask for the number corresponding to the Stock
    String s2 = JOptionPane.showInputDialog(null, "Please pick a number corresponding to the stock that you bought: \n " + list);
    stockNumber = Integer.parseInt(s1);






    OK NEXT THING I WANT TO DO IS ASK HOW MUCH OF EACH STOCK SO IF THEY BUY 2 APPLE etc. how do i incorporate that??
    Last edited by joregorn; March 22nd, 2012 at 06:33 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Need help with calculating stock code.

    WANT TO DO IS ASK HOW MUCH
    Add another call to JOptionPane with the text of the message you want shown to the user. Get the response and convert it to a number as you have done already for the stockNumber.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need help with my code for calculating monthly payment on a loan
    By Marcella74 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 25th, 2012, 09:26 AM
  2. Need help correcting my code for calculating sexy prime pairs
    By BinaryPenguin14 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 23rd, 2011, 04:05 AM
  3. stock charts...
    By theChameleon in forum Java Theory & Questions
    Replies: 1
    Last Post: February 24th, 2011, 05:11 AM
  4. stock screener api java
    By thosecars82 in forum Java SE APIs
    Replies: 0
    Last Post: January 31st, 2010, 09:50 AM
  5. Java stock project help
    By lotus in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: July 12th, 2009, 04:16 AM