Question

In: Computer Science

Write a java program that asks the user for the starting X and Y position of...

Write a java program that asks the user for the starting X and Y position of a mouse cursor as well as the starting X and Y movement, then prints out its position until X < 0 or X >100

Example 2:

Enter the starting X position: 60

Enter the starting Y position: 60

Enter the starting X velocity: 4.7

Enter the starting Y velocity: 1

X:60    Y:60

X:64.7 Y:61

X:69.4 Y:63

X:74.1 Y:65

X:78.8 Y:67

X:83.5 Y:69

X:88.2 Y:71

X:92.9 Y:73

X:97.6 Y:75

X:102.3 Y:77

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new java program with name "CursorMovement.java" is created, which contains following code.

CursorMovement.java :

//import package
import java.util.*;
//java class
public class CursorMovement {
//entry point of program , main() method
   public static void main(String[] args) {
       //creating object of Scanner class
       Scanner sc=new Scanner(System.in);
       //asking user starting X position
       System.out.print("Enter the starting X position: ");
       double x=sc.nextDouble();//reading x position
       //asking user starting y position
       System.out.print("Enter the starting Y position: ");
       double y=sc.nextDouble();//reading y position
       //asking user starting x velocity
       System.out.print("Enter the starting X velocity: ");
       double velocityX=sc.nextDouble();//reading X velocity
       //asking user starting y velocity
       System.out.print("Enter the starting Y velocity: ");
       double velocityY=sc.nextDouble();//reading Y velocity
       //using while loop
       while(x>0 && x<=100)
       {
           //print X and Y position
           System.out.printf("X:%.1f",x);
           System.out.print(" ");//used for space
           System.out.printf("Y:%.1f",y);
           System.out.println();//used for new line
           x=x+velocityX;//increment position by adding velocity
           y=y+velocityY;//increment position by adding velocity
       }
       System.out.printf("X:%.1f",x);
       System.out.print(" ");//used for space
       System.out.printf("Y:%.1f",y);
          
   }

}

======================================================

Output : Compile and Run CursorMovement.java to get the screen as shown below

Screen 1 :CursorMovement.java

Screen 2 :

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
IN JAVA write a program that asks a user for a maximum of 20 user-inputted elements...
IN JAVA write a program that asks a user for a maximum of 20 user-inputted elements and create an array. Then, write a Merge Sort function with recursion (in the main) that takes the user inputted elements in the array, sorts them, and prints them back.
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a java program that asks the user for a number n and gives them the...
Write a java program that asks the user for a number n and gives them the possibility to choose between computing the sum and computing the product of 1,…,n. Example of running this program: Enter an integer number n: __7________ Enter Sum or Product: __Sum__________________________________ Program output: Sum of 1 ... 7 Sum or Product: Sum Sum = 28 Now second sample of second execution Enter an integer number n: __5__________________________________ Enter Sum or Product: __Product__________________________________ Program output:  Product of 1...
Write a program in Java that first asks the user to type in today's price of...
Write a program in Java that first asks the user to type in today's price of one dollar in Japanese yen, then reads U.S. dollar values and converts each to yen. Use 0 as a sentinel to denote the end of dollar input. THEN the program reads a sequence of yen amounts and converts them to dollars. The second sequence is terminated by another zero value.
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to enter a number of seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to...
In Java: Write a program that generates a random number and asks the user to guess...
In Java: Write a program that generates a random number and asks the user to guess the number and keeps track of how many guesses it took If the user input is negative or zero then the loop must stop reading further inputs and display how many guesses they used If they guess the correct number display a message telling them they got it and exit the program If they guess the wrong number (but still a legal guess) you...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT