Ask Question
13 March, 09:43

Complete method printPopcornTime (), with int parameter bagOunces, and void return type. If bagOunces is less than 2, 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

code:

import java. util. Scanner;

public class PopcornTimer {

public static void printPopcornTime (int bagOunces) {

/ * Your solution goes here * /

}

public static void main (String [] args) {

printPopcornTime (7);

}

}

+1
Answers (1)
  1. 13 March, 10:21
    0
    import java. util. Scanner;

    public class PopcornTimer{

    public static void printPopcornTime (int bagOunces) {

    if (bagOunces < 2)

    System. out. println ("Too small");

    else if (bagOunces > 10)

    System. out. println ("Too large");

    else

    System. out. println ((6*bagOunces) + " seconds");

    }

    public static void main (String[] args) {

    printPopcornTime (7);

    }

    }

    Explanation:

    Inside the printPopcornTime method, check the bagOunces using if-else structure.

    If bagOunces is smaller than print "Too small", if bagOunces is greater than 10 print "Too large", else multiply bagOunces with 6 and print the result followed by "seconds".

    Since given parameter, 7, in the example is neither smaller than 2 nor greater than 10, 7 will be multiplied by 6 which is equal to 42, and "42 seconds" will be printed
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Complete method printPopcornTime (), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "Too small". If ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers