Not Yet Answered # Beginner Java Programming Help

Discussion Starter andrewriebel Discussion Starter andrewriebel gowans07 mk12345

0

Here is the code I've produced so far:

```
package quadrant;
import java.util.Scanner;
public class Quadrant
{
public static int x1;
public static int y1;
public static int x2;
public static int y2;
public static int Coordinate1Quadrant(int x1, int y1)
{
int coordinate1quadrant = 0;
if (x1 > 0 && y1 > 0)
{
coordinate1quadrant = 1;
}
else if (x1 < 0 && y1 > 0)
{
coordinate1quadrant = 2;
}
else if (x1 > 0 && y1 > 0)
{
coordinate1quadrant = 3;
}
else if (x1 > 0 && y1 < 0)
{
coordinate1quadrant = 4;
}
return coordinate1quadrant;
}
public int Coordinate2Quadrant(int x2, int y2)
{
int coordinate2quadrant = 0;
if (x2 > 0 && y2 > 0)
{
coordinate2quadrant = 1;
}
else if (x2 < 0 && y2 > 0)
{
coordinate2quadrant = 2;
}
else if (x2 > 0 && y2 > 0)
{
coordinate2quadrant = 3;
}
else if (x2 > 0 && y2 < 0)
{
coordinate2quadrant = 4;
}
return coordinate2quadrant;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Please enter a value for x1: ");
x1 = input.nextInt();
System.out.print("Please enter a value for y1: ");
y1 = input.nextInt();
System.out.print("Please enter a value for x2: ");
x2 = input.nextInt();
System.out.print("Please enter a value for y2: ");
y2 = input.nextInt();
if (Coordinate1Quadrant == Coordinate2Quadrant)
{
System.out.print("These coordinates are in the same quadrant.");
}
else if ( (Coordinate1Quadrant == 1 && Coordinate2Quadrant == 2)
||(Coordinate1Quadrant == 1 && Coordinate2Quadrant == 4)
||(Coordinate1Quadrant == 2 && Coordinate2Quadrant == 3)
||(Coordinate1Quadrant == 2 && Coordinate2Quadrant == 1)
||(Coordinate1Quadrant == 3 && Coordinate2Quadrant == 2)
||(Coordinate1Quadrant == 3 && Coordinate2Quadrant == 4)
||(Coordinate1Quadrant == 4 && Coordinate2Quadrant == 1)
||(Coordinate1Quadrant == 4 && Coordinate2Quadrant == 3))
{
System.out.print("These coordinates are in adjacent quadrants.");
}
else if ( (Coordinate1Quadrant == 1 && Coordinate2Quadrant == 3)
||(Coordinate1Quadrant == 2 && Coordinate2Quadrant == 4)
||(Coordinate1Quadrant == 3 && Coordinate2Quadrant == 1)
||(Coordinate1Quadrant == 4 && Coordinate2Quadrant == 2))
{
System.out.print("These coordinates are in opposite quadrants.");
}
}
}
```

0

I'm getting a lot of errors with this, and I'm pretty sure it stems with the methods I set up (Coordinate1Quadrant and Coordinate2Quadrant). I'm not profecient with them whatsoever. If someone could please show me the right direction I'd grealy appreciate it.

0

you need to declare the variables Coordinate1Quadrant and Coordinate2Quadrant in the main method.

0

check your spelling of Coordinate1Quadrant and Coordinate2Quadrant

and you haven't given parameters to the method Coordinate1Quadrant and Coordinate2Quadrant.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:

```
try
{
Runtime run = Runtime.getRuntime();
Process pr = ...
```

I don’t want at this stage work on a big separate project as I've already got plenty ...

Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.

btn_addline :

`Private Sub btn_addline_Click(ByVal ...`