Car - public Car (int xOff, int yOff) { xOffset = xOff;...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // Car.java Author: Lewis and Loftus // // Solution to Programming Project 6.17 //******************************************************************** import java.awt.Color; import java.awt.Graphics; class Car { // Coordinates if car is drawn at position 0,0 private int[] x = {0, 0, 20, 25, 70, 80, 105, 110}; private int[] y = {35, 15, 15, 0, 0, 15, 15, 35}; private int[] xCurrent = new int[x.length]; private int[] yCurrent = new int[y.length]; private int xOffset = 0, yOffset = 0; private final Color carColor = Color.blue; //----------------------------------------------------------------- // Sets up the graphical car with the specified information. //-----------------------------------------------------------------
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public Car (int xOff, int yOff) { xOffset = xOff; yOffset = yOff; for (int scan=0; scan < x.length; scan++) { xCurrent[scan] = x[scan] + xOffset; yCurrent[scan] = y[scan] + yOffset; } } //-----------------------------------------------------------------// Draws the car at a particular x and y offset. //-----------------------------------------------------------------public void draw (Graphics page) { page.setColor (carColor); page.fillPolygon (xCurrent, yCurrent, x.length); page.setColor (Color.black); page.fillOval (13+xOffset, 28+yOffset, 14, 14); // rear wheel page.fillOval (83+xOffset, 28+yOffset, 14, 14); // front wheel page.drawLine (15+xOffset, 18+yOffset, 15+xOffset, 3+yOffset); } }...
View Full Document

Ask a homework question - tutors are online