CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  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(System.in);
    			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

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.