Can any one help me make java script that running test below
Can any one help me make java script that running test below questions?
Problem A: Kitty & Food (20 points) Write a program that Makes a 400x400 window. Draw a cat at the point (350, 350) and some food at the point (50, 50). (Your artistic skills will not be evaluated.) Whenever the user presses an arrow key, move the cat in that direction 50 spaces. If the cat goes on the boarder of the window (on either 0 or 400), stop the program saying the cat fell off the wolrd (see Example 1).
If th cat reaches the food, point (50, 50), without falling off, then say the have won and quit the game (Example 2).
Hint: Key input is done by the KeyListener class. To see what input you get, run the getKeyCode() method and compare to KeyEevent.VK_LEFT and the other directions.
Example 1 (user input is underlined, bold is descriptive not verbatim):
Example 2 (user input is underlined, bold is descriptive not verbatim):
You win!
Problem B: Doggie (20 points) Expand part A, except add a dog at point (200, 200). Every time the cat moves (with the arrow keys) the dog moves but only 25 units rather than the cats 50. If the dog is within 50 units in both x and y, then the cat should be caught by the dog and you lose the game (print “Dog bites you!”). For example, if the cat is at (300,250) and the dog is at (250, 200) and after the cat moves it is at (300, 300) and the dog is at (250, 250). The dog is within 50 units in both x and y and your program should stop.
The dog should always move towards the cat, in whichever axis is greater. For example, if the dog is 200 x-units away from the cat and 100 y-units away, the dog should move closer in the x-direction. If there is a tie, move in the y-direction. This movement should be determined after the cat has moved, so first the cat moves, then the dog tries to move closer. Given the setup of the game, the only way for the cat to get past the dog is to move up or left from the current position 6 times, then go towards the food. (Once the cat passes the dog, it can take detours and still win.)
Example 1 (user input is underlined, bold is descriptive not verbatim):
(window closes)
You win!
Test your program using not only the example data above, but other cases as well. And revise your program until you are sure it is correct.
(press upl (press right) (window closes) You fall off the worldSolution
Please find below the java program for youe help :
import java.awt.*;
import java.awt.event.*;
public class Cat extends Frame{
public static void main(String[] args) {
Cat m=new Cat();
m.setVisible(true);
m.setSize(610,450);
m.setTitle(\"My Home\");
m.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void paint(Graphics s)
{
int x[]={400,350,50};
int y[]={400,350,50};
int n=3;
//This will set the gray background for frame
this.setBackground(Color.gray);
//This will set the yellow color for rectangle
s.setColor(Color.yellow);
s.fillRect(300, 200, 150, 100);
//This will set the blue color for another rectangle-door
s.setColor(Color.blue);
s.fillRect(350, 210,50, 60);
//This will draw a line below the cat
s.drawLine(350, 280, 400, 280);
//This will set dark gray for the food
s.setColor(Color.darkGray);
s.fillPolygon(x,y,n);
//This will set cyan color for Cat
s.setColor(Color.cyan);
s.fillOval(100, 100, 60, 60);
//This will draw a line - the bottom most line of drawing
s.drawLine(50, 300, 600, 300);
//To display some text
s.setColor(Color.black);
s.drawString(\"My Cat\", 275, 350);
}
}