Question

IN JAVA PLEASE!!! Program 1: Stay on the Screen! Animation in video games is just like...

IN JAVA PLEASE!!!

Program 1: Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we want to track an object and detect if it goes off the left or right side of the screen (that is, it’s X position is less than 0 and greater than the width of the screen, say, 100).

Write a program that asks the user for the starting X and Y position of the object as well as the starting X and Y velocity, then prints out its position each frame until the object moves off of the screen. Design (pseudocode) and implement (source code) for this program.

Sample run 1:

Enter the starting X position: 50

Enter the starting Y position: 50

Enter the starting X velocity: 4.7

Enter the starting Y velocity: 2

X:50 Y:50

X:54.7 Y:52

X:59.4 Y:54

X:64.1 Y:56

X:68.8 Y:58

X:73.5 Y:60

X:78.2 Y:62

X:82.9 Y:64

X:87.6 Y:66

X:92.3 Y:68

X:97 Y:70

X:101.7 Y:72

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
import java.io.*;

public class Main
{
   public static void main(String[] args) throws IOException{
      
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  
System.out.println("Enter X position");
       double x = Double.parseDouble(br.readLine().trim());
      
       System.out.println("Enter Y position");
       double y = Double.parseDouble(br.readLine().trim());

System.out.println("Enter X velocity");
       double vx = Double.parseDouble(br.readLine().trim());
      
       System.out.println("Enter Y position");
       double vy = Double.parseDouble(br.readLine().trim());
      
       System.out.println("required output is:");

       while(true)
       {
           if((x>=0 && x<=100) && (y >= 0 && y <= 100))
           {
               System.out.println("X:" + x + " Y:" + y);
               x = x + vx;
               y = y + vy;
           }
           else
           {
               break;
           }
       }
   }
}

Add a comment
Know the answer?
Add Answer to:
IN JAVA PLEASE!!! Program 1: Stay on the Screen! Animation in video games is just like...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java...Stay on the Screen! Animation in video games is just like animation in movies – it’s...

    Java...Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we want to track an object and detect if it goes off the left...

  • Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles....

    Modify the NervousShapes program so that it displays equilateral triangles as well as circles and rectangles. You will need to define a Triangle class containing a single instance variable, representing the length of one of the triangle’s sides. Have the program create circles, rectangles, and triangles with equal probability. Circle and Rectangle is done, please comment on your methods so i can understand */ package NervousShapes; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class...

  • ***This is a JAVA question*** ------------------------------------------------------------------------------------------------ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*;...

    ***This is a JAVA question*** ------------------------------------------------------------------------------------------------ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.imageio.*; import javax.swing.*; import javax.swing.event.*; public class DrawingPanel implements ActionListener { public static final int DELAY = 50; // delay between repaints in millis private static final String DUMP_IMAGE_PROPERTY_NAME = "drawingpanel.save"; private static String TARGET_IMAGE_FILE_NAME = null; private static final boolean PRETTY = true; // true to anti-alias private static boolean DUMP_IMAGE = true; // true to write DrawingPanel to file private int width, height; // dimensions...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT