Figure 1: Scenario example: a self-driving car approaches a pedestrian crossing but its breaks fail. Your
algorithm needs to decide between two cases. Left: The car will continue ahead and drive through the
crossing resulting in one elderly man, one pregnant woman, one boy, and one dog losing their lives.
Right: The car will swerve and crash into a concrete barrier resulting in the death of its passengers: one
women, one man, and one baby. Note that the pedestrians abide by the law as they are crossing on a
green signal.
1
. Gender must include the types FEMALE and MALE as well as a default option UNKNOWN, but
can also include more diverse options if you so choose.
2
. BodyType includes the types AVERAGE, ATHLETIC, and OVERWEIGHT as well as a default
option UNSPECIFIED.
The Character Class should implement the constructors as depicted in Figure 2. Make sure the empty
constructor initializes all attributes with appropriate default values.
Age should be treated as a class invariant for which the following statement always yields true: age >= 0.
1
.2 Classes Inheriting from Character.java
Create at least two concrete classes that directly inherit from the abstract class Character:
1
2
. Person.java: scenarios are inhabited by people who exhibit a number of characteristics (e.g., age,
gender, body type, profession etc.). In the scenarios, each person is either considered to be a
passenger or a pedestrian. A person can be you.
. Animal.java: animals are part of the environment we live in. People walk their pets so make sure
your program accounts for these, at least for: cats and dogs.
1.2.1 The Class Person.java
This class represents a human in the scenarios. On top of its parent methods, the class Person must at
least include the following public methods:
•
the constructor Person(int age, Profession profession, Gender gender, BodyType bodytype, boolean
isPregnant).
ꢀ