THIS
IS THE KEY. Mr. Merlis has put it online
so you can go over your answers.
Do
not in any way sell, reproduce, or do anything else with it.
(It’s
not exactly a hot item on Ebay, anyway.)
/* AP
JAVA MIDTERM
* NAME:
* DATE:
*
* PART 1:
Please place the correct letter answer next to the number below.
* 1. C
* 2. C
* 3. B
* 4. D
* 5. A
* 6. C
* 7. E
* 8. D
* 9. D
* 10. C
* 11. C
* 12. E
* 13. D
* 14. E
* 15. E
* 16. D
* 17. B
* 18. D
* 19. A
* 20. E
* 21. C
* 22. A
* 23. B
* 24. D
* 25. C
*
*
=============================================================================
* THE ANSWERS BELOW ARE
NOT THE ONLY ONES THAT WOULD WORK... plus i’ve given some
* other options.
* PART 2: Please
answer the two questions and their associated parts in a clear
* and concise fashion below.
When done with the test, print it.
*
* QUESTION 1:
The Toy Problem
*
* Part A
* public boolean isAgeAppropriate(int age)
* {
* if(age >=
lBound && age <= UBound) // or just return(age >= lBound
&& age <= UBound);
* return true;
*
* return false;
* }
*
* Part B
* public ArrayList toySelection(int anAge, String aGender)
* {
* ArrayList possToys = new ArrayList();
* for(int i = 0; i
< toyList.size(); i++)
* {
* Toy toCheck = ((Toy)toyList.get(i));
* if(
toCheck.isAgeAppropriate(anAge) && (toCheck.getGender().equals(aGender)
|| toCheck.getGender().equals(either)))
* possToys.add(toCheck);
* }
* return possToys;
* }
*
*
* QUESTION 2:
The Motor Company
*
* Part A
* public class Car
* {
* //instance variables
* private String
itsType; // couple, sedan, wagon
* private String
itsExtColor;
* private String
itsIntColor;
* private ArrayList
itsOptions;
*
* public Car(String
type, String extColor, String intColor, ArrayList options)
* { ... }
*
* public String
getExtColor() { ... }
* public String
getIntColor() { ... }
* public String
getItsType() {...}
* public boolean
hasOption(String feature) {...}
* public String
toString() {...}
* }
*
* Part B
*
* public int
carsProducedWith(String feature)
* {
* int count = 0;
* for(int i = 0;
i<carsProduced.size(); i++)
* {
* Car curCar = (Car)carsProduced.get(i);
* if(curCar.hasOption(feature))
* count++;
*
* }
*
* return count;
* }
*
*
* Part C
*
* public boolean
hasOption(String feature)
* {
* if(itsOptions.contains(feature))
// this general idea
* return true;
*
* return false;
* }
*
* // or loop through
the information and use .equals()
* //---header--
* for(int l = 0; l
< itsOptions.size(); l++)
* {
* if(feature.equals((String)itsOptions.get(l)))
* return true;
* }
* return false;
*
*
*/