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 assistance with Returning Value Methods

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need assistance with Returning Value Methods

    Here is the code that I have thus far...I am a novice and completely stuck. The objectives that I must complete are as follows:

    1.) Write a method called calcTotalPrice which takes two parameters:

    -Quantity of an item

    -Price of an item

    (calcTotalPrice will return the amount needed to buy that quantity at that price.)

    2.) Write a main method that asks the user for 3 different items, the desired quantity and the price of each item. Call calcTotalPrice to calculate the total price of each item. Use String.printf to format the output.





    for(int i=0; i<=3; i++){
    quantity1 = JOptionPane.showInputDialog("Hello, please enter the quantity of Item"+i);
    Integer.parseInt(quantity1);
    price1 = JOptionPane.showInputDialog("Hello, please enter the quantity of Item"+i);
    java

  2. #2
    Member
    Join Date
    Apr 2014
    Posts
    93
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: Need assistance with Returning Value Methods

    Hi,

    Please be more specific. What exactly are you stuck on, and what have you tried? And please post the complete code (inside code tags); I can't tell whether you've defined the 'quantity1' and 'price1' variables before trying to use them.

    One definite problem though is you're not doing anything with the return value from Integer.parseInt(quantity1). You'll need new int variables for both quantity and price, assigned to the return value from Integer.parseInt(). Then you'll have the two ints needed to multiply.

Similar Threads

  1. Returning methods to main() and other methods
    By jonmackey22 in forum Object Oriented Programming
    Replies: 4
    Last Post: September 25th, 2014, 04:36 PM
  2. HW Help: Returning Values with Methods
    By santafebound in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 25th, 2014, 02:33 AM
  3. Replies: 8
    Last Post: February 10th, 2014, 06:03 AM
  4. methods returning zero's ???
    By fakeClassy in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 3rd, 2011, 05:53 PM
  5. [SOLVED] Java Beginner: Help with methods and returning values (hailstone program)
    By alf in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 14th, 2010, 06:28 PM

Tags for this Thread