logo Practice-It logo


Language/Type: Java file processing Scanner
Author: Whitaker Brand

Write a method named pizza that accepts as its parameter a Scanner for an input file. Imagine that a college dorm room contains several boxes of leftover pizza. A complete pizza has 8 slices. The pizza boxes left in the room each contain either an entire pizza, half a pizza (4 slices), or a single slice. Your method's task is to figure out the fewest boxes needed to store all leftover pizza, if all the partial pizzas were consolidated together as much as possible.

Your pizza method will read lines from its input Scanner where each line of data represents the contents of the pizza boxes in one dorm room. These contents are written as whole, "half", or "slice" in either upper or lower case, separated by at least one space. You should print to the console the number of pizza boxes necessary to store all the slices of pizza out of the total. You must use a whole number of boxes. For example, if there are 10 total slices of pizza in a dorm room, 2 pizza boxes are needed: one for the first whole pizza, and one for the final 2 slices. Note that some lines might be blank, meaning that the dorm room contains no pizzas; output for such a case is shown below.

For example, consider the following input file representing 5 dorm rooms (note that the fourth is blank):

slice half slice whole whole half half half
whole HALF   WhoLE half WHOLE  WhOlE  Slice         half sLICe halF
WHOLE slice   WHOLE SLICE whole SLICE    whole slice WHOLE half


For the input above, your method should produce the following output:

5 / 8 pizza boxes used
7 / 10 pizza boxes used
6 / 10 pizza boxes used
0 / 0 pizza boxes used
1 / 1 pizza boxes used

The format of your output must exactly match that shown above. You may assume that the Scanner contains at least 1 line of input, and that no tokens other than whole/half/slice.

Type your solution here:

This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.

Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.