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

Thread: Need some JAVA basic programming help

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

    Angry Need some JAVA basic programming help

    My teacher doesn't teach in my class jsut tells us to read the chapters and do homework. So I have no real understanding for java at all. I need someone to help me start a basic program and possibly guide me through. I am trying to teach myself which is difficult.


    This is the question
    Create the program below in as a Java file in TextPad.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.


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

    Default Re: Need some JAVA basic programming help

    Have you written any code yet? What questions do you have about your assignment?
    Make a list of the steps the program must do and then write the code for the first step, compile it and execute it.
    Fix the problems and go on to the second step.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some JAVA basic programming help

    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..

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some JAVA basic programming help

    my problem is converting the Apple or Dell stock to an actual numerical value
    What is a "stock"? Is it a String containing numeric digits?
    See the API doc for the Integer class, it has a static method for converting a String to an int value.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some JAVA basic programming help

    What? I am very new to java only been using it for a week. I have no idea what any of that means.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some JAVA basic programming help

    Which part don't you understand?
    String
    numeric digits
    int
    convert String to int
    Integer class
    static method
    API doc
    Here is a link to the API doc. You should save it and use it often. I use it many times a day.
    http://download.oracle.com/docs/cd/E...se/6/docs/api/

    Find the name of the class in the lower left, click it and the doc will be shown in the main frame.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some JAVA basic programming help

    API has not been taught to be yet therefore I cannot use it. I am only suppose to use chapter 1 and 2 in my text book.

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

    Default Re: Need some JAVA basic programming help

    I just want to say apple= 1$ if that makes sense or DELL= 2 etc,,, so that I can use those to multiple

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some JAVA basic programming help

    Then look in chapters 1 & 2 for the classes and methods you need.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some JAVA basic programming help

    I dont understand them....

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some JAVA basic programming help

    What classes and methods are in the textbook?
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some JAVA basic programming help

    I can not see your textbook so you will have to be the one to read it.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Basic Java Program Help
    By Nuggets in forum Java Theory & Questions
    Replies: 15
    Last Post: January 18th, 2012, 12:47 AM
  2. Re: Basic Java Program Help
    By Tanushri in forum Java Theory & Questions
    Replies: 3
    Last Post: January 18th, 2012, 12:43 AM
  3. Basic Obj programming help! thanks
    By mclaren93 in forum Object Oriented Programming
    Replies: 1
    Last Post: November 17th, 2011, 07:45 PM
  4. Basic java question
    By erosgol in forum Java Theory & Questions
    Replies: 5
    Last Post: September 2nd, 2011, 05:24 PM
  5. Few very basic Java questions.
    By 01001010 in forum Java Theory & Questions
    Replies: 2
    Last Post: February 13th, 2010, 01:14 PM