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

  Client class to test implementation of the vector class

Write a client class to test your implementation of the Vector3D class thatyou implemented. Name the package in which this class is defined (projectname) vector3dapp.

  Design an adt for a two-color

Design an ADT for a two-color, double-stack ADT that consists of two stacks one "red" and one "blue" and has as its operations color-coded versions of the regular stack ADT operations.

  Write java code to read integers from an input file

write java code to read integers from an input file and write only the odd numbers to an output file. the two file names will be provided on the command line as the input file followed by the output file.

  Technical community blog

Write a blog article for a coding/technical community blog

  Implementation activities of software development

Analysis, design, and implementation activities of software development

  Write methods in java

1. int countVowels (String s) That for a given string s, return number of vowels in s.

  Implement/update specific methods for the dfs of a graph

implement/update specific methods for the DFS of a graph; for at least 2 graphs (1 being the provided one), show the DFS order of vertices in the graph, and for each node,

  List various bindings that are needed to determine semantics

List the various bindings that are required to determine the semantics when the statement is executed. For each binding, indicate the binding time used for the language.

  A mini game made in java using zen graphics

a mini game made in Java using Zen graphics .

  Write a program that asks a user for a file name and prints

Write a program that asks a user for a file name and prints the number of characters, words, and lines in that file.

  Complete the twins() method

Complete the twins() method, which takes an integer argument n and prints all the sets of twin primes that are less than n, one pair per line

  Write a code fragment that would printout the multiplication

Write a code fragment that would printout the multiplication table for the number 3 multiplied by (1-10) .

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