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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started