CSCI 161 Exam #2, Spring 2024 ----------------------------- Problem 1: ---------- a) You could either count up by sevens, printing each value, or count by 1 and print the values that are divisible by 7. In either case, it's a count-controlled loop and should therefore use a FOR. b) An array makes it much easier to work with multi-dimensional collections of data than an ArrayList does, though the simpler syntax and ability to hold primitive types make them appealing for any situation where the size of the collection is fixed. c) Otherwise you have no control over when and how they are changed by code from outside of the class. You won't be able to enforce any limits on the number of sides a Die has, for example, or the size of a Circle, or keep those values from changing. (It would be bad for the number of sides on a Die to change after creation -- the history array's size wouldn't match anymore!) Problem 2: ---------- public int mystery(Die d) { int a = 1; int b = 0; while(a != b) { a = b; b = d.roll(); System.out.println("Rolled a "+b); } return b; } a) The mystery method takes a Die object as input, rolls it until it returns the same value twice in a row, then returns that rolled value. (It also prints each of the rolls made during the process.) b) With a 1-sided die, it would stop almost immediately since it can only roll 1's. After two rolls it would stop and return a 1. Problem 3: ---------- public void borrowRandomNote(Notebook other) { Random rng = new Random(); int index = rng.nextInt(other.notes.size()); notes.add(other.notes.get(index)); } Problem 4: ---------- public int getVotesFor(String name) { for(int i=0; i