Question: Write a java program that demonstrates recursion. This program can be in a java GUI frame or as a console application. On this one it

Write a java program that demonstrates recursion. This program can be in a java GUI frame or as a console application. On this one it is up to you. (It would probably work better as a console program for this particular program.)

The input for this program is a number of boxes. Ask the user for this with a textbox or a prompt on the command line.

Demonstrate recursion with a function called LoadTruck() that takes a number of boxes to be packed as a parameter. This function should print Truck Loaded and subtract 5 from the number of boxes and recursively call itself until there are less than 5 boxes. That time through it should print There are not enough to pack another truck.

(If you wish to use a GUI, it might be best to print the lines by concatenating them onto the text in a textArea along with a newline character. There may be other ways you can think of to do this in a GUI using other controls. Anyway you display the trucks loaded is fine.)

This program must have a recursive method. If you use a loop to load the trucks it will not count for any of the points for this one. This lab is to demonstrate recursion.

Example of output for 23 boxes:

Truck Loaded

Truck Loaded

Truck Loaded

Truck Loaded

There are not enough to pack another truck.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!