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

  Rank document relevance by number of times input keyword

You should also rank document's relevance by number of times input keyword occurs in document. How to rank document's relevance by number of times input keyword occurs in document.

  Perform an internal and external competitive environmental

perform an internal and external competitive environmental scan for your organization. the organizations name is flat

  The rmo csms marketing subsystem

Using Microsoft Visio or an open source alternative such as Dia, create a use case graphic rendering that shows all actors and all use cases for the RMO CSMS marketing subsystem. Note: The graphically depicted solution is not included in the requi..

  Bullhow ismight the strategic plan be communicated to

bullhow ismight the strategic plan be communicated to various levels o management a variety of differing teams and to

  Selecting bit mapped or vector graphics

For each of the provide a detailed rational for selecting bit mapped or vector graphics when they used in a web based application,

  Aggression and violence in the media

Consider the context in which this aggression or violence occurred and ways in which it can lead to desensitization.

  Determine when would a transition be appropriate

Some animation schemes include slide transitions and some do not. Determine when would a transition be appropriate? When would it not be appropriate?

  Framework of user interface design

design of user interfaces, natural mapping, GUI applications, web page design different to designing for printed media, risks exposed in this "phone as individual proxy" approach, interaction designers of ubicomp applications, Storyboards are usual..

  Draw a square logo for dog food

draw a square logo for dog food, withi a large bag in the middle, and write text on the bag. please make it attractive to people. with colors and any techniques that you want to use

  What are the factors affecting picture composition

Define picture composition What are the factors affecting picture composition. Elaborate on each factor Describe the basic lines present in a composition

  The facts presented in the infographic

To get a different perspective on customer centric business models that often have some sort of "value added" think about what you, as a customer, have experienced. Do you have loyalty to any ape of product or company.

  Choose two 2 public corporations in an industry with which

choose two 2 public corporations in an industry with which you are familiar - one 1 that has acquired another company

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