Add a draw() method to horse class.

Assignment Help JAVA Programming
Reference no: EM13166556

Add a draw() method to your Horse class. You will also need to create a couple of Horses in your DrawPanel class, and call the draw() method for each Horse from the paintComponent() method. There is no need to modify the DrawPanelDriver class.

 

Horse class


public class Horse

 

{

 

private String name;

 

private int age;

 

private String breed;

 

Horse()

 

{

 

name = "Horse";

 

age = 10;

 

breed = "American";

 

}

 

public void setName(String n)

 

{

 

name = n;

 

}

 

public void setAge(int a){

 

age = a;

 

}

 

public void setBreed(String b)

 

{

 

breed = b;

 

}

 

public String getName()

 

{

 

return name;

 

}

 

public int getAge()

 

{

 

return age;

 

}

 

public String getBreed()

 

{

 

return breed;

 

}

 

public void eat()

 

{

 

System.out.println( name + " is eating" );

 

}

 

public void sleep()

 

{

 

System.out.println( name + " is sleeping" );

 

}

 

public void walk()

 

{

 

System.out.println( name + " is walking" );

 

}

 

public void trot()

 

{

 

System.out.println( name + " is trotting" );

 

}

 

}

 

DrawPanel class

import java.awt.Graphics;

import javax.swing.JPanel;

 

public class DrawPanel extends JPanel

{

private Cow c1 = new Cow( 20,30, "Bob" );

private Cow c2 = new Cow( 50,70, "Dave" );

public void paintComponent( Graphics g )

{

// call super class method

super.paintComponent ( g );

g.drawLine(0,0, 200,175);

c1.draw( g );

c2.draw( g );

c1.sleep( g );

 

}// end paintComponent

}// end DrawPanel

 

DrawPanelDriver class

 

// Application to display DrawPanel

// No need to modify this code

import javax.swing.JFrame; // window base class

 

public class DrawPanelDriver

{

public static void main( String[] args )

{

// create a DrawPanel object

DrawPanel panel = new DrawPanel();

// create a new frame (window) to hold the panel

JFrame application = new JFrame();

// exit when the application is closed

application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

// put our panel in the JFrame

application.add( panel );

application.setSize( 250, 250 ); // frame size

application.setVisible( true );

}

}// end of DrawPanelDriver

 

 

Reference no: EM13166556

Questions Cloud

Division by zero is not possible : You must also ensure that division by zero is not possible. If the user tries to divide by zero, the calculation should not be attempted, and an error message should appear in the Result text box.
How system access big date to maximum in usage? : How system access big date to maximium in usage?
Opportunity to work with both c style strings : The focus of this lab is on using strings. You will have an opportunity to work with both C style strings and the string data type. This lab also gives you an opportunity to use what you have learned previously
Who is holding return real time big data analysis : Who is holding return realtime bigg data analyssis? what is the future of data big?
Add a draw() method to horse class. : Add a draw() method to your Horse class. You will also need to create a couple of Horses in your DrawPanel class, and call the draw() method for each Horse from the paintComponent() method. There is no need to modify the DrawPanelDriver class.
Major social factors in negotiation : What are the major social factors in negotiation? Who are the possible parties? How are they different, and how does this affect the negotiation?
Keep track of the size of the array : Keep track of the size of the array so that you cannot exceed the array boundaries. The implementation details (i.e. the private members)of your class are up to you, but the class should have the following public interface
The user is assumed to enter the list in sorted order : Make sure you FULLY test your program! Make sure to run your program multiple times, inputting combinations of values that will test all possible conditions for your IF statements and loops. Also be sure to test border-line cases.
Interaction between the customer and the machine : In Python:Simulate a cash register or ATM including the interaction between the customer and the machine (i.e. assume that you are automating the responses)

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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