Implement abstract class vehicle and concrete subclasses car

Assignment Help Computer Graphics
Reference no: EM13891649

Implement an abstract class Vehicle and concrete subclasses Car and Truck. A vehicle has a position on the screen. Write methods draw that draw cars and trucks as follows:

Then write a method randomVehicle that randomly generates Vehicle references, with an equal probability for constructing cars and trucks, with random positions. Call it 10 times and draw all of them.

Use the following class as your main class:
import javax.swing.JComponent;
import javax.swing.JFrame;

/**
This program draws cars and trucks in random order.
*/
public class RandomVehicleViewer
{
public static void main(String args[])
{
JFrame frame = new JFrame();
final int FRAME_WIDTH = 600;
final int FRAME_HEIGHT = 600;

frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JComponent component = new RandomVehicleComponent();
frame.add(component);
frame.setVisible(true);
}
}

You need to supply the following classes in your solution:
RandomVehicleComponent
Car
Truck

Use the following class in your solution:
import java.awt.Graphics2D;

/**
This class represents a vehicle.
*/
public abstract class Vehicle
{
private int xleft;
private int ytop;

/**
Construct a Vehicle object.
*/
public Vehicle()
{
xleft = 0;
ytop = 0;
}

/**
Draw the specified vehicle.
@param g2 the graphics context
*/
public abstract void draw(Graphics2D g2);

/**
Set the location of the vehicle.
@param x the x coordinate
@param y the y coordinate
*/
public void setLocation(int x, int y)
{
xleft = x;
ytop = y;
}

/**
Returns the x coordinate of the left-top corner of the vehicle
@return the x coordinate
*/
public int getX()
{
return xleft;
}

/**
Returns the y coordinate of the left-top corner of the vehicle
@return the y coordinate
*/
public int getY()
{
return ytop;
}

public abstract int getHeight();
public abstract int getWidth();
}

import java.awt.Graphics2D;

/**
This class represents a vehicle.
*/
public abstract class Vehicle
{
private int xleft;
private int ytop;

/**
Construct a Vehicle object.
*/
public Vehicle()
{
xleft = 0;
ytop = 0;
}

/**
Draw the specified vehicle.
@param g2 the graphics context
*/
public abstract void draw(Graphics2D g2);

/**
Set the location of the vehicle.
@param x the x coordinate
@param y the y coordinate
*/
public void setLocation(int x, int y)
{
xleft = x;
ytop = y;
}

/**
Returns the x coordinate of the left-top corner of the vehicle
@return the x coordinate
*/
public int getX()
{
return xleft;
}

/**
Returns the y coordinate of the left-top corner of the vehicle
@return the y coordinate
*/
public int getY()
{
return ytop;
}

public abstract int getHeight();
public abstract int getWidth();
}

import javax.swing.JComponent;
import javax.swing.JFrame;

/**
This program draws cars and trucks in random order.
*/
public class RandomVehicleViewer
{
public static void main(String args[])
{
JFrame frame = new JFrame();
final int FRAME_WIDTH = 600;
final int FRAME_HEIGHT = 600;

frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JComponent component = new RandomVehicleComponent();
frame.add(component);
frame.setVisible(true);
}
}

Reference no: EM13891649

Questions Cloud

Method of investigation : Summarize the article (1-2 paragraphs) Analyze the article, examining the strength of its thesis/hypothesis, method of investigation, analysis of data, and conclusions (4-5 paragraphs)
Does this package meet the requirement : An experimentalpackage and its support structure wh ich are to be place on board a space station act as an underdamped spring - mass system w ith a force constant of 2.1X106N/mand mass 108kg. Does this package meet the requirement
Symptoms of depression : What regions of the brain and neurotransmitters are associated with the symptoms of depression? What regions are activated by stress? How are the stress response and depression related?
Implement abstract class vehicle and concrete subclasses car : Implement an abstract class Vehicle and concrete subclasses Car and Truck. A vehicle has a position on the screen. Write methods draw that draw cars and trucks as follows
Provide a rationale for the u.s. publicly traded company : Provide a rationale for the U.S. publicly traded company
The pew internet and american life project : Read the sidebar about the Pew Internet and American Life Project at http://www.pewinternet.org (Links to an external site.) in Chapter 19.  Go to the Web site and browse through the reports.  Select a report and briefly summarize it in a short parag..
Show turing machine recognizes class of truing-recognizable : Computation is defined as usual except that the head never encounters an end to the tape as it moves leftward. Show that this type of Turing machine recognizes the class of Truing-recognizable languages.

Reviews

Write a Review

Computer Graphics Questions & Answers

  Essential elements of a design pattern

configuration of an Iterator pattern, patterns could be used in a Library System, Singleton, Template, Decorator, Façade,What does Alexander means by the following declaration "But it is impossible to form anything which has the temperament of natu..

  A rental car manager estimates the number of full-size

a rental car manager estimates the number of full-size sedans rented per week 5 so that she can maintain adequate

  Create a three dimensional game

Need an interaction for player so player can jump from one allowed location to another - the target is now a sphere that bounces inside the volume of play.

  Ethernet equipment to modernize the network

An older network using ten baseT technology needs an upgrade. The network haves a total of 220 workstations and ten servers and has a network diameter of three-hundred meters.

  Read the article values-based service brands narratives

read the article values-based service brands narratives from ikea by edvardsson from the readings for this module.

  Find graph theory concepts that correspond to social concept

Suppose we make a graph in which nodes are people and edges correspond to some form of social interaction, such as "talk to" or "socializes with" Find graph theory concepts that correspond to social concepts such as popularity, cliques, and hermi..

  Develop a simulation of an elevator

Develop a simulation of an elevator - devise and implement a second strategy - Develop a simulation of an elevator that travels between floors 1 and N where N is an input.

  The rationale for a firms cooperate-level strategy is

the rationale for a firms cooperate-level strategy is applied to cooperative strategy. select one of the three types of

  Create the movement of the car from the left

Create the movement of the car from the left o the screen to the right - Add the 2 wheels to the vehicle using the GlutWireSphere

  Develop a grayscale image consisting of grid

Develop a grayscale image consisting of an 8 x 8 grid with vertical line in the first column. Compress into JPEG format and decompress.

  Build agraphical user interface for a text editor

Using BlueJ, Design and build aGraphical user interface for a text editor. Users should be able to enter text,edit, scroll, etc. Consider functions for formatting (font faces, style, andsize) and a character/word-count function.

  Specify a triangle with three mouse presses

Write a program that allows the user to specify a triangle with three mouse presses. After the first mouse press, draw a small dot. After the second mouse press, draw a line joining the first two points.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd