Directions: Given the following problem descriptions, write appropriate method c
ID: 3817773 • Letter: D
Question
Directions: Given the following problem descriptions, write appropriate method call and method definitions for each problem(In Java).
A) Write a method call and a method definition for a method named getName that will prompt for the user’s first name and return it to the calling method where it will be stored in a variable named firstName.
B) Write a method call and a method definition for a method named tenTimes that will accept a double argument, and return a double value that is ten times the value of the argument. The calling method will printout the returned value.
Explanation / Answer
A)
Method defination:-
String getName();
Method call:-
String getName(){
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter your first name ");
String name = scanner.next();
return name;
}
B.
Method defination:-
double tenTimes(double x);
Method call:-
double tenTimes(double x){
return (x*(10.0));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.