Professional Documents
Culture Documents
IMPORTANT:
If your code does not run because you did not correctly follow the instructions
provided, you will be allowed to re-submit this assignment. However, 5 points
will be discounted from your maximum grade. Resubmission will be allowed
one time only! Please make sure to clarify any questions you may have about
the setup and/or submission with the TA before you resubmit the lab. Also be
sure to check this checklist before submitting.
PROBLEM PROMPTS
Part A:
For this problem, you will develop the infrastructure for a game meant to
teach healthy habits. In particular, this game focuses on what you ingest (eat,
drink, take) and what you do (activities), and their effect on your overall health.
For this problem, you are given two interfaces:
1. The Ingestible interface, which specifies behavior for all ingestible
Example:
Part B:
Example:
Encourager[] encouragers = {
new Dog(),
new Friend("Jing", 20),
new Friend("Aly", 21),
new Nature(),
new Parent("Mom", 50),
new Parent("Dad", 51)
};
Person[] people = {
new Friend("Jing", 20),
new Friend("Aly", 21),
new Friend("Aly", 18),
new Friend("Aly", 35),
new Parent("Mom", 50),
new Parent("Dad", 51)
};
Arrays.sort(people);
for (Person p : people) {
System.out.println(p);
}
/*
* The above prints out:
*
* Name: Aly, Age: 18
* Name: Aly, Age: 21
* Name: Aly, Age: 35
* Name: Dad, Age: 51
* Name: Jing, Age: 20
* Name: Mom, Age: 50
*/
Example:
// Checking subSequence:
CharSequence endOfFirstHalf = firstHalf.subSequence(15, 20);
System.out.println(endOfFirstHalf); // prints "7 8 9"
// Checking charAt:
firstHalf.charAt(7); // returns '3'
firstHalf.charAt(19); // returns '9'
// Checking length:
firstHalf.length(); // returns 20
firstHalf.subSequence(5, 15).length(); // returns 10