Ask Question
9 June, 01:33

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);

}

}

+2
Answers (1)
  1. 9 June, 02:43
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers