(JAVA) write a program IN JAVA that uses a method called quadrant that accepts a
ID: 3768538 • Letter: #
Question
(JAVA) write a program IN JAVA that uses a method called quadrant that accepts as parameters a pair of double values representing an (x, y) point and returns the quadrant number for that point. Recall that quadrants are numbered as integers from 1 to 4 with the upper-right quadrant numbered 1 and the subsequent quadrants numbered in a counterclockwise fashion: xid-111609318_1 Notice that the quadrant is determined by whether the x and y coordinates are positive or negative numbers. Return 0 if the point lies on origin (point 0,0). return a -1 if the point is on the x axis, return -2 if the point is on the y axis. For example, the call of quadrant(-2.3, 3.5) should return 2 and the call of quadrant(4.5, -4.5) should return 4. The values for x and y should be entered by the user, and the where the point is located should be output by another method
Name the class project3............................
(WHAT I HAVE SO FAR .....STILL HAS SOME ERRORS IN THEM THE COMPILER SAYS... NEED HELP CORRECTING IT!
public class project3{
public static int quadrant(double x,double y){
if(x > 0 && y > 0){
return 1;
}else if( x < 0 && y > 0){
return 2;
}else if( x < 0 && y < 0){
return 3;
}else if( x > 0 && y < 0){
return 4;
}else
return 0;
}
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int x = in.nextDouble();
int y = in.nextDouble();
System.out.println("Quadrant number :" + quadrant(x,y));
}
}
Explanation / Answer
import java.util.Scanner;
public class project3 {
public static int quadrant(double x, double y) {
if (x > 0 && y > 0) {
return 1;
} else if (x < 0 && y > 0) {
return 2;
} else if (x < 0 && y < 0) {
return 3;
} else if (x > 0 && y < 0) {
return 4;
} else
return 0;
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print(" Enter x:");
double x = in.nextDouble();
System.out.print("Enter y:");
double y = in.nextDouble();
System.out.println("Quadrant number :" + quadrant(x, y));
}
}
OUTPUT:
Test1:
Enter x:12.4
Enter y:17.8
Quadrant number :1
Test2:
Enter x:-2.3
Enter y:3.5
Quadrant number :2
Test3:
Enter x:-15.2
Enter y:-3.1
Quadrant number :3
Test4:
Enter x:4.5
Enter y:-42.0
Quadrant number :4
Test5:
Enter x:0.0
Enter y:3.14
Quadrant number :0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.