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

  Modifying the product program through gui

Modify the product Program to use a GUI. The GUI should show the data one product at a time, including the product number, the name of the item, the number of units in stock.

  Differentiate between a bitmap image and a vector image

Differentiate between a bitmap image and a vector image Explain the following terms

  Describe how joint application design

Describe how joint application design

  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

  1 identify the 5 elements of strategy for home depot2 do a

1. identify the 5 elements of strategy for home depot.2. do a swot analysis for home depot and provide recommendations

  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

  Write an easy to use gui application

easy-to-use GUI application

  When can restructuring be seen as a positive corporate

when can restructuring be seen as a positive corporate strategic move? explain how shareholder value is created through

  Critical review and application due date05-jun-2013 return

critical review and application due date05-jun-2013 return date 28-jun-2013 length3000 words submission method options

  Does the above statement apply to microeconomics

Does the above statement apply to microeconomics or macroeconomics? Why? Think about the cases of government intervention that create a different price compared to the price-finding mechanism of supply and demand.

  It security report and presentation

The presentation must include appropriate graphics, and may be in a Microsoft PowerPoint presentation format.Online students will submit a presentation that must include detailed speaker notes.

  Quantify the objectives of the various projects the

quantify the objectives of the various projects the objectives of the sbu and the objectives of the parent company and

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