Skip to main content
Contents
Search Book
close
Search Results:
No results.
Dark Mode Prev Up Next Scratch ActiveCode Profile
title here
\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 8.6 Write-Methods-WE3-P1
Subgoals for Writing Methods.
Define method header based on problem
Define return statement at the end
Determine types of logic (expression, selection, loop, etc.)
Define internal variables
Subsection 8.6.1
Exercises Exercises
1.
Q46: Put the code in the right order to create a public method that returns a String and accepts an integer parameter and returns a flavor of ice cream. The method is called from main as follows:
System.out.println(flavors(1));
System.out.println(flavors(5));
public static String flavors (int one) {
---
String flavor;
---
if (one == 1)
flavor = "chocolate";
---
else if (one == 2)
flavor = "vanilla";
---
else
flavor = "strawberry";
---
return flavor;
}
2.
Q47: Put the code in the right order to create a method that returns a String and accepts as parameters a double and a String, and concatenates the two values as a temperature along with its base scale. The method is called from main as follows:
System.out.println ( temps(32.5, "F"));
System.out.println ( temps(0.05, "C"));
public static String temps (double t, String base) {
---
String temp;
---
temp = "temperature is " + t + " " + base;
---
return temp;
}
You have attempted
of
activities on this page.