Practice Questions: Week 08


Simple Traversals

1. Write a program that generates a random GlobalCredit using GlobalCredit.getRandom(). Print each element of the collection by using a loop to traverse the collection.

2. Write a program that generates a random Portfolio using Portfolio.getRandom(). Print each element of the collection by using a loop to traverse the collection using iterator-based traversal.

3. Write a program that generates a random Portfolio using Portfolio.getRandom(). Traverse the collection in reverse order by using a regular for loop that counts from the last index to the first index and print each element of the traversal.

4. Write a program that generates a random Student using Student.getRandom(). Print each course taken by the student along with the corresponding grade.

5. Write a program that generates a random Student using Student.getRandom(). Adjust each course grade up one letter grade (ie. change F's to E's, E's to D's, D's to C's and so on; obviously A's remain unchanged).

Search

6. Write a program that takes one command line argument (assumed to an integer greater than or equal to zero). Your program should generate a random GlobalCredit using GlobalCredit.getRandom(). Print each card in the collection on a separate line; every card with a balance greater than the input amount should be output with a '*' at the beginning of the line.

7. Modify your solution to Question 6 so that every card with an available credit greater than the input amount is output with a '*' at the beginning of the line.

8. Write a program that takes one command line argument (assumed to an integer greater than or equal to zero). Your program should generate a random GlobalCredit using GlobalCredit.getRandom(). Print each card in the collection with a card number smaller than the input number on a separate line. Then print the remaining cards in the collection (one per line).

9. Write a program that generates a random Portfolio using Portfolio.getRandom(). Print each investment having a stock whose name starts with a letter in the range A-M on a separate line. Then print the remaining investments (one per line).

10. Write a program that generates a random Student using Student.getRandom(). Print every first year course taken by the student and the corresponding course grade (one per line). Then do the same for all of the second year courses, followed by all of the third year courses, followed by all of the fourth year courses.


Too Hard for a Short Test

11. Write a program that generates a random Student using Student.getRandom(). Find the minimum number of courses that need to be retaken so that the GPA increases by at least 1.0; assume that the student will get an A for every course retaken. Output the list of courses that need to be retaken. [Note: it may not be possible to raise the GPA by 1.0]