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

  Write the logical expression in postfix notation.

Given symbols p, q, r, and s for propositions. Draw the binary tree representation of the logical expression ((p || r) && ! p ) || s) && (q || r). Write the logical expression in postfix notation.

  Java program to print strings given at command line

Write down program Average.java to print strings which it is given at command line, one per line. If nothing is given at command line, then print "No arguments".

  Write a java applet for grade of gas in costco gas station

Write a java applet (not a java application program) for costco gas station. The applet will first ask you whether you are a costco customer, then the grade of gas you want to use.

  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

  Technical community blog

Write a blog article for a coding and technical community blog.

  Write a program called word guessing game.

Write a program called Word Guessing Game. Open the file FourLetterWords.txt and write the contents into an array of Strings (the file has 87 words in it).

  Java program that will prompt the user to input a file

Write a Java program that will prompt the user to input a file (document) in order to count the frequency of each word. This program will display the frequency of each word sorted alphabetically or by frequency (depending on the preference of the use..

  Client server monitoring system project design

client server monitoring system project design. The server adminstation can send messages to the clients and DESIGN WITH JAVA NETBEANS AND GUI.

  The data file being used contains records

The data file being used contains records with an employee's name, the number of hours they worked, and their hourly pay rate. Write a program to read the records of information and output (to the Output window or a dialog box) the employee's name..

  Create java program to find number of days left in that year

Create a Java program called "DaysLeftInYear.java" that outputs the number of days left in that year. use the calendar class to represent dates. Use the DateFormat class to display the current date in the output.

  Construct java program named collegelist

Construct a set of classes for a college to use in many student service and personnel applications. Classes you require to design include following:

  One-dimensional array to solve the

In C#, Use a one-dimensional array to solve the following problem. A company pays its salespeople on a commission basis. The salespeople each receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who gros..

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