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 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 protocol
object oriented programming protocol  What is object oriented programming protocol? Is it different from objective c protocol programming?? Thanks
Advertisements
Object Oriented Programming in PHP
Object 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 II
Object 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
What are the features and advantages of OBJECT ORIENTED PROGRAMMING?
What are the features and advantages of OBJECT ORIENTED PROGRAMMING?  What are the features and advantages of OBJECT ORIENTED PROGRAMMING
object oriented programming data science
object 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 Beginners
object 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 Beginners
Object-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 Java
OOPS 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
An Overview of Java      Java is a programming language      Java is Object Oriented Programming
; Java as a programming language Java is an Object oriented application programming language developed by Sun Microsystems. Java is a very powerful general-purpose programming language.  
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
Introduction to POJO (Plain Old Java Object) Programming Model
Introduction to POJO (Plain Old Java Object) Programming Model... Object). It is a Java object that doesn't extend or implement some specialized... looks up a stub object of the @Producer interface from the JNDI. The auto
ModuleNotFoundError: No module named 'fast-orient'
ModuleNotFoundError: No module named 'fast-orient'  Hi, My Python... 'fast-orient' How to remove the ModuleNotFoundError: No module named 'fast-orient' error? Thanks   Hi, In your python environment
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
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.  (Aim:- The main aim of this experiment is reusability of code and getting idea about classifying objects , identifying
object
object  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
Programming
Programming  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
programming
create 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
programming
constructor 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
programming
Construct 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 Beginners
Java 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
org.sonatype.nexus - nexus-orient version 3.7.1-02 Maven dependency. How to use nexus-orient version 3.7.1-02 in pom.xml?
org.sonatype.nexus  - Version 3.7.1-02 of nexus-orient Maven dependency? How to use  org.sonatype.nexus  - Version 3.7.1-02 of nexus-orient in pom.xml? How to use nexus-orient version 3.7.1-02 in pom.xml? Learn to use
org.sonatype.nexus - nexus-orient version 3.26.0-04 Maven dependency. How to use nexus-orient version 3.26.0-04 in pom.xml?
org.sonatype.nexus  - Version 3.26.0-04 of nexus-orient Maven dependency? How to use  org.sonatype.nexus  - Version 3.26.0-04 of nexus-orient in pom.xml? How to use nexus-orient version 3.26.0-04 in pom.xml? Learn to use
org.sonatype.nexus - nexus-orient version 3.12.0-01 Maven dependency. How to use nexus-orient version 3.12.0-01 in pom.xml?
org.sonatype.nexus  - Version 3.12.0-01 of nexus-orient Maven dependency? How to use  org.sonatype.nexus  - Version 3.12.0-01 of nexus-orient in pom.xml? How to use nexus-orient version 3.12.0-01 in pom.xml? Learn to use
org.sonatype.nexus - nexus-orient version 3.23.0-03 Maven dependency. How to use nexus-orient version 3.23.0-03 in pom.xml?
org.sonatype.nexus  - Version 3.23.0-03 of nexus-orient Maven dependency? How to use  org.sonatype.nexus  - Version 3.23.0-03 of nexus-orient in pom.xml? How to use nexus-orient version 3.23.0-03 in pom.xml? Learn to use
org.sonatype.nexus - nexus-orient version 3.26.0-04 Maven dependency. How to use nexus-orient version 3.26.0-04 in pom.xml?
org.sonatype.nexus  - Version 3.26.0-04 of nexus-orient Maven dependency? How to use  org.sonatype.nexus  - Version 3.26.0-04 of nexus-orient in pom.xml? How to use nexus-orient version 3.26.0-04 in pom.xml? Learn to use
Introduction to POJO (Plain Old Java Object) Programming Model
Introduction to POJO (Plain Old Java Object) Programming Model... features of added by Sun Microsystems in EJB 3.0 is POJO (Plain Old Java Object). It is a Java object that doesn't extend or implement some specialized
object of object class
object of object class  what do u mean by "object of object class
Performing Object Introspection
Performing Object Introspection         In OOP based programming language object introspection is a technique to determining the elements(properties
Maven Repository/Dependency: org.sonatype.nexus | nexus-orient
Maven Repository/Dependency of Group ID org.sonatype.nexus and Artifact ID nexus-orient. Latest version of org.sonatype.nexus:nexus-orient dependencies. # Version Release Date 1
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 Object
PHP 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
Maven dependency for org.sonatype.nexus - nexus-orient version 3.44.0-01 is released. Learn to use nexus-orient version 3.44.0-01 in Maven based Java projects
of nexus-orient released The developers of   org.sonatype.nexus - nexus-orient project have released the latest version of this library on 14 Dec 2022, the released version of  org.sonatype.nexus - nexus-orient library
Maven dependency for org.sonatype.nexus - nexus-orient version 3.43.0-01 is released. Learn to use nexus-orient version 3.43.0-01 in Maven based Java projects
of nexus-orient released The developers of   org.sonatype.nexus - nexus-orient project have released the latest version of this library on 07 Nov 2022, the released version of  org.sonatype.nexus - nexus-orient library
Maven dependency for org.sonatype.nexus - nexus-orient version 3.42.0-01 is released. Learn to use nexus-orient version 3.42.0-01 in Maven based Java projects
of nexus-orient released The developers of   org.sonatype.nexus - nexus-orient project have released the latest version of this library on 23 Sep 2022, the released version of  org.sonatype.nexus - nexus-orient library
Maven dependency for org.sonatype.nexus - nexus-orient version 3.41.1-01 is released. Learn to use nexus-orient version 3.41.1-01 in Maven based Java projects
of nexus-orient released The developers of   org.sonatype.nexus - nexus-orient project have released the latest version of this library on 18 Aug 2022, the released version of  org.sonatype.nexus - nexus-orient library

Ads