} public void drawCar(Graphics g) { super.drawCar(g); drawWindows(g); drawRoof(g); } private void drawWindows(Graphics g) { g.setColor(Color.white); g.fillRect(xPos+10,yPos+30,25,30); g.fillRect(xPos+45,yPos+30,25,30); g.fillRect(xPos+80,yPos+30,25,30); g.fillRect(xPos+115,yPos+30,25,30); } private void drawRoof(Graphics g) { Polygon roof = new Polygon(); roof.addPoint(xPos-15,yPos+20); roof.addPoint(xPos,yPos); roof.addPoint(xPos+150,yPos); roof.addPoint(xPos+165,yPos+20); g.setColor(carColor); g.fillPolygon(roof); } } Train Case Study, Stage #6 (Create a Caboose Class) Here is the final subclass of the RailCar superclass. It is appropriate since we are now looking at the Caboose class in figure 14.32. It has two windows and it has a raised roof, called a for part of the car. This It is placed at the end of a cupola, long freight train and most of the time it is colored red. Our final subclass is shown in figure 14.33.
} public void drawCar(Graphics g) { super.drawCar(g); drawWindows(g); drawRoof(g); } private void drawWindows(Graphics g) { g.setColor(Color.white); g.fillRect(xPos+10,yPos+30,25,30); g.fillRect(xPos+45,yPos+30,25,30); g.fillRect(xPos+80,yPos+30,25,30); g.fillRect(xPos+115,yPos+30,25,30); } private void drawRoof(Graphics g) { Polygon roof = new Polygon(); roof.addPoint(xPos-15,yPos+20); roof.addPoint(xPos,yPos); roof.addPoint(xPos+150,yPos); roof.addPoint(xPos+165,yPos+20); g.setColor(carColor); g.fillPolygon(roof); } } Train Case Study, Stage #6 (Create a Caboose Class) Here is the final subclass of the RailCar superclass. It is appropriate since we are now looking at the Caboose class in figure 14.32. It has two windows and it has a raised roof, called a cupola, for part of the car. This It is placed at the end of a long freight train and most of the time it is colored red. Our final subclass is shown in figure 14.33.
Text14-FocusOnOOP-Polymorphism.docx