-
February 26th, 2013, 05:06 PM
#1
Value-returning Method
Code:
public static void main(String[] args) {
double cups, ounces;
System.out.println("Enter number of cups");
cups = getCups(); :wave:
ounces = CupsToOunces(cups);
displayResults(cups,ounces);
System.exit(0);
}
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();.
-
March 1st, 2013, 07:12 AM
#2
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.
-
March 12th, 2013, 04:40 PM
#3
Re: Value-returning Method
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|