Problem Statement
Create a class Truckloads that contains a method numTrucks that is given numCrates (the number of crates at the warehouse) and loadSize (the maximum number of crates that will fit in a truck) and that returns the number of trucks required.
Definition
- Class:
- Truckloads
- Method:
- numTrucks
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int numTrucks(int numCrates, int loadSize)
- (be sure your method is public)
Constraints
- numCrates will be between 2 and 10,000, inclusive.
- loadSize loadSize will be be between 1 and (numCrates - 1), inclusive.
Examples
14
3
Returns: 6
After the first division we have two piles each with 7 crates. Each of these piles must be divided giving us 2 piles of 3 and 2 piles of 4. The piles with 4 crates must be further divided giving us 2 piles of 3 and 4 piles of 2. Each of these piles fits into a truck, so we need 6 trucks.
15
1
Returns: 15
We will eventually end up with 15 piles, each with just 1 crate.
1024
5
Returns: 256
1024 divides in half very nicely. We eventually end up with 256 piles, each containing 4 crates.
10000
79
Returns: 128
894
22
Returns: 64
10000
1
Returns: 10000
15
5
Returns: 4
21
5
Returns: 5
12
5
Returns: 4
11
5
Returns: 3
2
1
Returns: 2
3
2
Returns: 2
10000
9999
Returns: 2
7777
1
Returns: 7777
9999
1111
Returns: 16
8888
1111
Returns: 8
1298
13
Returns: 128
1023
4
Returns: 256
1024
4
Returns: 256
1025
4
Returns: 257
8192
4
Returns: 2048
8191
4
Returns: 2048
8193
4
Returns: 2049
8193
16
Returns: 513
8191
32
Returns: 256
8192
256
Returns: 32
33
2
Returns: 17
5
2
Returns: 3
1024
5
Returns: 256
100
2
Returns: 64
3
2
Returns: 2
10000
1
Returns: 10000
7
2
Returns: 4
17
3
Returns: 8
17
2
Returns: 9
29
5
Returns: 8
14
3
Returns: 6
155
5
Returns: 32
4
3
Returns: 2
9999
2
Returns: 5903
15
3
Returns: 7