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.


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 with joptionpane

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

    Default Need help with calculating stock with joptionpane

    Here is the question I am trying to answer....

    Write a program that asks 3 people (include your first name and the first names of 2 other people) to enter the name of the stock purchased (for example, IBM, Google, Microsoft, Coca Cola), the number of shares of stock purchased, and the price per share of stock purchased. Each person must pay his or her stock broker a 2 percent (.02) commission for his or her stock transaction. Request the input data from each person by using the appropriate JOptionPane dialog box. Create a formula to calculate stock value (hint: stock price per share * number of stock shares purchased), commission (hint: stock value * .02), and total amount paid for the stock (hint: stock value plus commission). Using the appropriate JOptionPane dialog box, display 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.
    HTML Code:
    public class Stock
    	 public static void main(String[] args)
    		 //Declare variables
            int numberofShares = 0,priceperShare = 0,valueofShares=0;
            double commission = 0.00; double totalStockcost = 0.00; double StockCom = 0.00;
           //Ask for First and Last name
           String name = "";
    	   		String Firstname = JOptionPane.showInputDialog(
    	                           null, "Please enter your first name: ");
    	       	String 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);
            String s3= JOptionPane.showInputDialog(null, "Number of Stock Purchased");
    So I have gotten where I can input all the information, but my problem is converting the Apple or Dell stock to an actual numerical value. So that I can multiply that value, by the amount purchased to figure out total spent on stock..

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,475 Times in 2,426 Posts

    Default Re: Need help with calculating stock with joptionpane

    Is this the same question:

    Why have two threads?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need help with calculating stock code.
    By joregorn in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 22nd, 2012, 07:06 PM
  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
  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