Value-returning Method
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: Value-returning Method

  1. #1
    Join Date
    Jul 2012

    Value-returning Method

    public static void main(String[] args) {
    		double cups, ounces;
    		System.out.println("Enter number of cups");
    	        cups = getCups(); :wave:
    		ounces = CupsToOunces(cups);
    		public static double getCups(double numberOfCups)
    			Scanner input = new Scanner(;
    			numberOfCups = input.nextDouble();
    			return numberOfCups;

    Can you guys advise on the method call getCups();.

  2. #2
    Join Date
    Aug 2011
    West Yorkshire, U.K.

    Re: Value-returning Method

    You do not need to pass in the argument (double numberOfCups) to getCups. You should declare numberOfCups as a double within the method.
    You could make the method more resilient. What would happen if the user entered a string (e.g. "Hello") or a negative number?
    You could pass the question string "Enter number of cups" as a String argument, check that the user enters a sensible value and return the value if it is, otherwise provide some guidance and ask the question again.

  3. #3
    Join Date
    Jul 2012

    Re: Value-returning Method

    Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center