Question: Problem Set 7 For questions 1-5 enter your answers using a text editor like notepad++. 1. The makeABid methodincludes the following two statements: Bid bid
Problem Set 7 For questions 1-5 enter your answers using a text editor like notepad++.
1. The makeABid methodincludes the following two statements:
Bid bid = new Bid(bidder, value); Boolean successful = selectedLot.bidFor(bid); The bid variable is only used here as a placeholder for the newly created Bid object before it is passed immediately to the lots bidFor method. Rewrite these statements to eliminate the bid variable by using an anonymous object as seen in the enterLot method (Hint: see section 4.14.5 of the text).
2. Write a Java statement that declares a Java Class variable of type int called numberOfCalls and initializes it to zero.
3. Write a Java statement that declares a Java constant called interestRate and initializes it to 8.5%.
4. Write a Java statement that declares a Java constant called maxStudents and initializes it to 60.
5. Write a Java method header for a Class method called findMin() that returns the smallest integer in a list of integer values.
For questions 6 12, use BlueJ to create the specified class.
6. Create a class called GradeList that has a single field called grades that is an ArrayList of Integer objects.
7. Write a constructor that initializes grades to an empty ArrayList.
8. Write a method called fillGrades that allows the user to enter a specified number of grades into the grades collection from the keyboard. The number of grades to be read should be passed as a parameter. (Hint: Use a scanner object to read the grades and a while loop to read a grade the specified number of times).
9. Write a method called printGrades that prints the grades in the collection one grade per line.
10. Write a method called sortGrades that sorts the grades in the collection in ascending order (Hint: Check the documentation for the Collections class for a method to do this).
11. Write a method called findMaxGrade that returns the grade in the collection with the maximum value (Hint: Check the documentation for the Collections class for a method to do this).
12. Write a method called removeGrades that removes all occurrences of a specified grade in the collection. The specified grade should be passed as a parameter.
For questions 13 17, use BlueJ to create the specified class. You will need to look at section 6.6 of the text as well as the documentation for the HashMap class. 13. Create a class called Contacts with a single field called contactList that is of type HashMap. The keys are the contacts names (String) and the values are the phone numbers (String).
14. Write a constructor that initializes contactList to an empty HashMap.
15. Write a method called addContact that adds a new name and number to contactList.
16. Write a method called findNumber that returns the number of a contact specified by the name key.
17. Write a method called numberOfContacts that returns the number of contacts currently stored in contactList.
For Questions 18 20, enter your answers in a text editor like notepad++.
18. What happens when you add an entry to a map with a key that already exists in the map?
19. What happens when you add two entries to a map with the same value and two different keys?
20. What happens when you look up a value and the key does not exist in the map
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
