Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by "seconds". End with a newline. Example output for ounces = 7:
42 seconds
import java.util.Scanner;
public class PopcornTimer {
public void printPopcornTime(int bagOunces) {
/* Your solution goes here */
}
public static void main (String [] args) {
PopcornTimer popcornBag = new PopcornTimer();
popcornBag.printPopcornTime(7);
}
}
Answer in JAVA where it says solution goes here
The complete Java source code is given below.
import java.util.Scanner;
public class PopcornTimer
{
public void printPopcornTime(int
bagOunces)
{
//if loop to check
whether bagOunces value is less than 3 or not
//if it is true, then if
stmt will execute otherwise else part will execute
if(bagOunces<3)
System.out.println("Too small"); //print a
message
else
{
System.out.print(6*bagOunces+" seconds\n");
//print the output
}
}
public static void main (String []
args)
{
PopcornTimer popcornBag
= new PopcornTimer();
popcornBag.printPopcornTime(7);
}
}
If the indendations are not clear, then please refer the screenshot of the code given below.
The screenshot of the output is also given below.
Explanation
Hope this helps. Doubts, if any, can be asked in the comment section.
Get Answers For Free
Most questions answered within 1 hours.