The part of code I am struggling to get working is
Expand|Select|Wrap|Line Numbers
- public void add(RoadVehicle vehicle) {
- if (isFull()) {
- System.out.println("Queue is full! We cannot add any more vehicles to the Queue!");
- System.exit(1);
- } else {
- if (vehicle instanceof EmergencyVehicle && vehicle.isEmergency()) {
- addToFront(vehicle);
- } else {
- addToBack(vehicle);
- }
- }
- }
FireEngine class:
Expand|Select|Wrap|Line Numbers
- public abstract class EmergencyVehicle extends RoadVehicle {
- public boolean codeBlue = true;
- public EmergencyVehicle(String colour){
- super(colour);
- }
- public boolean isEmergency() {
- return codeBlue;
- }
- public void setEmergency(boolean newEmergency) {
- codeBlue = newEmergency;
- }
- }
Expand|Select|Wrap|Line Numbers
- public class FireEngine extends EmergencyVehicle {
- public FireEngine(String colour) {
- super (colour);
- }
- public FireEngine() {
- this("red");
- }
- public String toString () {
- if ("red".equals(colour)) {
- return "Fire Engine : CODEBLUE";
- } else
- return colour + " FireEngine.";
- }
- }
The error I get is:
error, cannot find symbol.
I don't need the exact solution, but I think it should work as I have got the extends in each class. Can anyone point out where it goes wrong? I realise that the code needs neatening up slighty!
When adding a vehicle to the queue, I use
Expand|Select|Wrap|Line Numbers
- FireEngine car1 = new FireEngine("red");