Question

Write a program to check the location of a point (x, y) in a 2D coordinate...

Write a program to check the location of a point (x, y) in a 2D coordinate system and display message differently: point (x, y) is on the original point; or is on the x-axle; or on the y-axle; or in one of 4 quadrants. When the point (x, y) is in a quadrant, the message should include quadrant information. For example, point (3, 5) is in quadrant I.

In Java Please

Homework Answers

Answer #1

JAVA Code:

import java.util.*;

//main class
public class sas 
{
  public static void main(String args[])
  {
    //scanner class
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter x & y coordinates: ");
    //taking inputs of x & y coordinates
    int x = sc.nextInt();
    int y = sc.nextInt();

    if(x==0 && y==0)  //condition for origin
    {
      System.out.println("point ("+x+","+y+") is on the original point"); //print output
    }
    else if(x==0 && y!=0)  //condition for y axis
    {
      System.out.println("point ("+x+","+y+") is on the y axle ");
    }
    else if(x!=0 && y==0)  //condition for x axis
    {
      System.out.println("point ("+x+","+y+") is on the x axle ");
    }
    else if(x>0 && y>0)   //condition for 1st quadrant
    {
      System.out.println("point ("+x+","+y+") is in quadrant 1 ");
    }
    else if(x<0 && y>0)  //condition for 2nd quadrant
    {
      System.out.println("point ("+x+","+y+") is in quadrant 2 ");
    }
    else if(x<0 && y<0)  //condition for 3rd quadrant
    {
      System.out.println("point ("+x+","+y+") is in quadrant 3 ");
    }
    else if(x>0 && y<0)  //condition for 4th quadrant
    {
      System.out.println("point ("+x+","+y+") is in quadrant 4 ");
    }
  }
}

OUTPUTS:

Know the answer?
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
Similar Questions
A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class,...
A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, “pointType”, that can store and process a point in the x-y plane. You should then perform operations on the point, such as setting the coordinates of the point, printing the coordinates of the point, returning thex-coordinate, and returning the y-coordinate. Also, write a program to testvarious operations on the point. x-y plane and you designed the class to capture the properties of a point...
Let the 2D point p have coordinates (x,y) with respect to the orthonormal coordinates system given...
Let the 2D point p have coordinates (x,y) with respect to the orthonormal coordinates system given by the origin o = (0,0) and the two basis vectors b1 = (1,0) and b2 = (0,1). The coordinate system is rotated by 45 degree. What are the new coordinates of the point p with respect to the new coordinates system? Provide an illustration!
Write a program named CheckZips that is used by a package delivery service to check delivery...
Write a program named CheckZips that is used by a package delivery service to check delivery areas. The program contains an array that holds the 10 zip codes of areas to which the company makes deliveries. (Note that this array is created for you and does not need to be changed.) Prompt a user to enter a zip code, and display a message indicating whether the zip code is in the company’s delivery area. For example if the user enters...
Java code Problem 1. Create a Point class to hold x and y values for a...
Java code Problem 1. Create a Point class to hold x and y values for a point. Create methods show(), add() and subtract() to display the Point x and y values, and add and subtract point coordinates. Tip: Keep x and y separate in the calculation. Create another class Shape, which will form the basis of a set of shapes. The Shape class will contain default functions to calculate area and circumference of the shape, and provide the coordinates (Points)...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
Three dimensions. Three point particles are fixed in place in an xyz coordinate system. Particle A,...
Three dimensions. Three point particles are fixed in place in an xyz coordinate system. Particle A, at the origin, has mass mA. Particle B, at xyz coordinates (3.00d, 2.00d, 4.00d), has mass 3.00mA, and particle C, at coordinates (–3.00d, 3.00d, –2.00d), has mass 3.00mA. A fourth particle D, with mass 3.00mA, is to be placed near the other particles. If distance d = 9.90 m, at what (a) x, (b) y, and (c) z coordinate should D be placed so...
Write a program that allows two players to play a game of tic-tac-toe. Use a twodimensional...
Write a program that allows two players to play a game of tic-tac-toe. Use a twodimensional char array with three rows and three columns as the game board. Each element in the array should be initialized with an asterisk (*). The program should run a loop that: • Displays the contents of the board array. • Allows player 1 to select a location on the board for an X. The program should ask the user to enter the row and...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
Write a complete recursive java program to compute the heights of the tick marks on a...
Write a complete recursive java program to compute the heights of the tick marks on a ruler. Assume that the length of the ruler is a power of 2 (say L=2^n, where n >=1) , and the marks are to be placed at every point between 0 and 2^n, not including the endpoints. The endpoints 0 and 2^n will have height 0. Here are the rules for computing the heights of the ticks for a ruler of length L=2^n: 1....