1. SUV 2. van 3. compact
and so on
Then, changing the same loop, add the price information from the second array to what is printed. Then add on a check of the third array, and add a note if the car is unavailable. So the output from the first loop ends up looking something like
1. SUV ($75.0 / day) 2. van ($25.0 / day) [unavailable] 3. compact ($30.0 / day)
and so on
☑ Next, using a second for loop, print the car types out again, but in reverse order, so the one at array index 9 prints first and the one at array index 0 prints last.
☑ Next, in another for loop, print a similar numbered list to the first one, but only of available cars, so if we had the same arrays as before we'd get the following, with the unavailable van left out:
1. SUV ($75.0 / day) 2. compact ($30.0 / day)
etc.
☑ Next, in another for loop, count how many compacts there are that are currently available. You will need to check if the current car is a compact and if it is available, so you need to look at information from two arrays. After the loop print something like
There are currently 3 compacts available to rent.
☑ Next, using another for loop, find the index (the position in the array) of the cheapest available vehicle.
Using the index you found, after the loop print something like
The cheapest available vehicle is a compact which costs $54.33 per day.
☑ Next, create a new array of doubles with the same
length as the prices array. Using another for loop, set the values
in the new array to twice the values from the prices array. Then
print the new array to check it is getting the right values.
Part A
In the following, write all loops so they would still work if the sizes of the arrays were changed.
☑ In a project, in a main, create an array of doubles of length 10, and give it values using special initialization.
Then write a loop that goes through the array, and after the loop report the largest and smallest number in the array, and the average of all the numbers.
☑ In the same main, create an array of 10 ints called howManyTimes and and array of 10 strings called words, both using special initalization.
Then go through these two arrays and print each element of words the number of times given in howManyTimes. So if howManyTimes[3] is 9 and words[3] is "hello" you would print "hello" 9 times. To do this you will need nested loops: an outer loop to move through the arrays, and an inner loop to print the words the right number of times. You DO NOT need a nested loop for each array.
☑ In the same main, create an array of 10 strings. Using nested loops, fill it with values so that each element is a string containing a number of x's based on the index, so the 0th element is "", the 1st element is "x" the 2nd element is "xx", and the 9th element is "xxxxxxxxx". (hint, one loop will move you through the array, the other will add the right number of x's to the current element).
Part B
Create a new package in the same project by right-clicking "Source Packages" and choosing Java Package under New... Name your package cards.
In this package, create classes Card, DeckOfCards, and DeckOfCardsTest and enter the code from the text into these (figures 7.9-7.11). (You need not include their comments)
Play with these classes and try to understand how they work, particularly their use of arrays.