27.0k views
5 votes
Complete method print PopcornTime(), with int parameter bag Ounces, and void return type. If bag Ounces is less than 2, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bag Ounces followed by "seconds". End with a newline.Example output for ounces = 7

User Roufamatic
by
5.1k points

1 Answer

5 votes

Answer:

public static void PopcornTime(double 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");

}

}

Step-by-step explanation:

A Complete Java code with a call to the method PopcornTime() is given below

public class TestClock {

public static void main(String[] args) {

//Calling the method

PopcornTime(2);

}

public static void PopcornTime(double 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");

}

}

}

The key logic in this code is the use of if/else if/else statements to check the different possible values of of bagOunces.

User Edenshaw
by
5.6k points