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 a program using an array that will store

Using java programing : Write a program using an array that will store input data. Prompt the user for and read 6 numbers between 70 and 90. Verify the numbers should be greater than 70 and less than 90. If the number is less than

  Prepare executable program and a dictionary program

Prepare executable program and a dictionary Program.

  Write java applet for costco gas station

Write a java applet 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: grade 87, 89, or 91.

  Write a method in java that uses a switch statement

Write a method in JAVA that uses a switch statement and takes a person's age using an integer parameter , then checks if the age is valid (0-110), and then RETURNS a string based on the age

  Write java program to enter number of marks

Write a java program called AverageMark.java. This program should allow the user to enter any number of marks and then display the minimum, maximum & average mark.

  Design a java program that has two parallel arrays

Design a java program that has two parallel arrays: a string array named people that is initialized with the names of seven of your friends, and a string array named phoneNumbers that is initialized with your friends phone numbers.

  A java program where the user designates

a java program where the user designates how many games they would like to play (for example user inputs 10 games) then they play the game, if lets say there is a tie after 10 games the game continues until either the user of the computer wins by 2

  Write program in java-calculate and display mortgage payment

Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage.

  Java program to create a tree

Java program to create a tree, generate class - BottomUpTwoThreeFourTree, BottomUpTwoThreeFourTree,

  Java program use breadth-first search closest broadcast

Write the java program which will use breadth-first search (which you implement as part of your program) to determine the closest broadcast vertex for each vertex in graph.

  A common useful equation

In physics, a common useful equation for finding the position s of a body in linear motion at a given time t, based on its initial position s0, initial velocity v0, and rate of acceleration a, is the following: ??= ??0+??0??+12????2. Write code to de..

  Modify each sorting algorithm

Modify each sorting algorithm so that it keeps track of the number of comparisons it performs and the number of exchanges (swaps) it performs during a single sorting operation. Keep track of these numbers using two long integer counters

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