Object Orient Programming
I have this program that needs to display multiple taxis. I have the code but there is an error. Could someone tell me where i am going wrong??
import java.awt.*;
import javax.swing.*;
public class TaxiCanvas extends JComponent
{
private Taxi[] taxis;
public TaxiCanvas(int numTaxis)
{
super();
makeTaxis(numTaxis);
}
private void makeTaxis(int numTaxis)
{
taxis = new Taxi[numTaxis];
for (int i=0; i<taxis.length; i++)
{
taxis[i] = new Taxi(i+1);
}
}
@Override
public void paint(Graphics g)
{
for (int i=0; i<taxis.length;i++)
{
int w = taxis[i].getBodyWidth();
int h = taxis[i].getBodyHeight();
int x = randomInt(w,getWidth() - w );
int y = randomInt(h, getHeight() - h);
taxis[i].display(g, x, y);
}
g.drawString(taxis.length + " taxis", getWidth()/2-30,20);
}
private int randomInt(int min, int max)
{
return (int)(Math.random()*(max - min +1)+min);
}
}
import java.awt.*;
import javax.swing.*;
public class TaxiFrame extends JFrame
{
public TaxiFrame()
{
super(" Taxi Project");
setSize(300,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocation(100,100);
getContentPane().setBackground(Color.CYAN);
getContentPane().add("Center", new TaxiCanvas(5));
setVisible(true);
}
public static void main(String[] args)
{
new TaxiFrame();
}
}
import java.awt.*;
public class Taxi
{
private TaxiCanvas canvas;
public int number;
private int BodyWidth;
private int BodyHeight;
public Taxi(TaxiCanvas canvas)
{
this.canvas = canvas;
}
public Taxi(int num)
{
number = num;
BodyWidth = 44;
BodyHeight = 20;
}
public int getBodyWidth()
{
return BodyWidth;
}
public int getBodyHeight()
{
return BodyHeight;
}
private int randomInt(int min, int max)
{
return (int)(Math.random()*(max - min +1)+min);
}
public void display(Graphics g , int x, int y)
{
int xSq = canvas.getWidth() / 120;
int ySq = canvas.getHeight() / 100;
// int xSq = 2;
// int ySq = 2;
// car body
g.setColor(Color.YELLOW);
int[] xbody ={x, x, x + (xSq*12),x +(xSq*18),x + (xSq*29),x +(xSq*37),x + (xSq*42),x + (xSq*44),x + (xSq*44)};
int[] ybody ={y-(ySq*6),y-(ySq*11),y-(ySq*14),y-(ySq*20),y-(ySq*20),y-(ySq*14),y-(ySq*14),y-(ySq*11),y-(ySq*6)};
g.fillPolygon(xbody, ybody, 9);
g.setColor(Color.BLACK);
g.drawLine(x,y-(ySq*6),x + (xSq*44),y-(ySq*6));
//left wheel
g.setColor(Color.BLACK);
g.fillOval(x +(xSq*3),y-(ySq*10),xSq*8,ySq*8);
//right wheel
g.setColor(Color.BLACK);
g.fillOval(x+(xSq*32), y-(ySq*10),xSq*8,ySq*8);
//left door
g.setColor(Color.LIGHT_GRAY);
g.drawRect(x+(xSq*13),y-(ySq*14),xSq*9,ySq*7);
g.setColor(Color.BLACK);
g.drawString(""+number,x+(xSq*16),y-(ySq*8));
g.setColor(Color.LIGHT_GRAY);
int[]xleftWin={x+(xSq*13),x+(xSq*18),x+(xSq*22),x+(xSq*22)};
int[]yleftWin={y-(ySq*14),y-(ySq*19),y-(ySq*19),y-(ySq*14)};
g.fillPolygon(xleftWin, yleftWin, 4);
//right door
int[]xleftDoor={x+(xSq*24),x+(xSq*24),x+(xSq*35),x+(xSq*35),x+(xSq*30)};
int[]yleftDoor={y-(ySq*7),y-(ySq*14),y-(ySq*14),y-(ySq*11),y-(ySq*7)};
g.drawPolygon(xleftDoor, yleftDoor, 5);
int[]xrightWin={x+(xSq*24),x+(xSq*24),x+(xSq*28),x+(xSq*35)};
int[]yrightWin={y-(ySq*14),y-(ySq*19),y-(ySq*19),y-(ySq*14)};
g.fillPolygon(xrightWin, yrightWin, 4);
}
}
View Answers
Related Tutorials/Questions & Answers:
Object Orient Programming Object Orient Programming I have this program that needs to display multiple taxis. I have the code but there is an error. Could someone tell me where i am going wrong??
import java.awt.*;
import javax.swing.*;
public
object oriented programming protocolobject oriented
programming protocol What is
object oriented
programming protocol? Is it different from objective c protocol
programming??
Thanks
Advertisements
Object Oriented Programming in PHPObject Oriented
Programming in PHP Hi,
Which version of PHP supports OOPS. How can I learn
Object Oriented
Programming in PHP?
Thanks
(adsbygoogle = window.adsbygoogle || []).push
Object Oriented Programming IIObject Oriented
Programming II Instructions:
->each class to be created must have
encapsulated fields, setters
and getters methods, and constructors
Create a class named "Paper" with the following attributes
object oriented programming data scienceobject oriented
programming data science Hi,
I am beginner in Data...:
object oriented
programming data science
Try to provide me good examples or tutorials links so that I can learn the
topic "
object oriented
programming object oriented programming - Java Beginnersobject oriented programming sir,
i read in the book tat
object oriented program exhibits recurring structures.
i want to know "what is meant by recurring structures?" Hi Friend,
Any structure to be occurred over
Object-Oriented programming - Java BeginnersObject-Oriented programming Write a program to display the names and salaries of 5 employees.Make use of a class and an array.The salary of each employee should increase by 5% and displayed back. Hi friend,
Code
Object Oriented Programming in JavaOOPS acronym for
Object Oriented
Programming is a model or concept that works
around objects and data.
Programming language like Java that follow the OOP... is an instance of a
class.
For a language to be an
Object Oriented
Programming Java using Netbeans Object Oriented Programming Java using Netbeans
Object Oriented
Programming I am trying to make a program that uses a main class and a separate class with one public method and one private method. The main method in the main class asks the user for 2
Java Object
Java
Object
Object is the basic entity of
object oriented
programming language.
Object... properties of the class or its group. Java
object
is an instance of the class. It takes
ModuleNotFoundError: No module named 'orient'ModuleNotFoundError: No module named '
orient' Hi,
My Python... '
orient'
How to remove the ModuleNotFoundError: No module named '
orient'... to install padas library.
You can install
orient python with following command
programming Java Constructor
programming for single and double constructor ... constructor,double parameter constor,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single
objectobject is it possible to create
object in the same class..?.
Yes, you can.
class CreateObject
{
CreateObject(){
System.out.println("I have an
object.");
}
public static void main(String[] args
ProgrammingProgramming Given a number n, write a
programming to determine its square root if it is possible, in the contraly case print an appropriate massege on the screen
programmingcreate a
object of constructor Java write a program which have... constor,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double parameter
programmingconstructor
object in java application programming write a program...,double parameter constor,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double
programmingConstruct a constructor of
object in Java programming write...,double parameter constor,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double
programming parameter constor,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double parameter
programming constor,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double parameter
programming,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double parameter constructor
programming,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double parameter constructor
programming constor,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double parameter
programming constor,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double parameter constructor
programming parameter constor,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double
programming parameter constor,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double
programming parameter constor,and the now when we create a
object of in this constructor he we tell the how much
object we created in the no argument.single or double
About Java Programming Language
About Java
Programming Language
Java is an
Object oriented application
programming
language developed by Sun Microsystems. Java is a very powerful general-purpose
programming Learning Java Programming for BeginnersJava is an
Object Oriented
Programming Language that was developed by Sun
Microsystems. It is based on C, C++
programming language but a tad better... are eyeing the vast
field of
programming and software development
Performing Object Introspection Performing
Object Introspection
In OOP based
programming language
object introspection is a technique to determining the elements(properties
Object are the basic units
of the
object-oriented
programming.
Objects are the part of our day... to begin thinking in terms of
object-oriented
programming. Objects are key to understanding
object-oriented
programming. Just look around and you'll find a lot
PHP Class ObjectPHP Class
Object:
In
object oriented
programming a class can be an abstract... apple, orange are the
object of this class.
Object is the instantiate..._TO_REPLACE_1
PHP
Object Class Example:
<?php
class AADS_TO_REPLACE_2
Learn Java Programming you proficient in the language.
Java is an
Object Oriented
Programming(OOP... in it, Learn Java
programming online with tutorials and simple examples... and mobile phones. Career in Java
programming is vast and that is why most
Is Java object oriented?Is Java
object oriented? Hi,
Is Java
object oriented?
Thanks
Hi,
Java is
object oriented
programming language. It is supports OPPS concepts:
Object
Class
Inheritance
Polymorphism
Abstraction
Encapsulation
All