0
import java.util.*;
import java.util.Scanner;
import java.io.*;


class Point
{
   /* Method to find the quadrant of both the points p and q*/

   public String quadrant(double xp, double yp, double xq, double yq){


        Scanner keyboard= new Scanner(System.in);
        System.out.print("Enter the first value for Xp: ");
        xp = keyboard.nextDouble();
        Scanner keyboard1 = new Scanner(System.in);
        System.out.print("Enter the first value for Yp: ");
        yp = keyboard.nextDouble();
        Scanner keyboard2= new Scanner(System.in);
        System.out.print("Enter the first value for Xq: ");
        xq = keyboard.nextDouble();
        Scanner keyboard3= new Scanner(System.in);
        System.out.print("Enter the first value for Yq: ");
        yq = keyboard.nextDouble();
       String p_quadrant=getQuadrant(xp,yp);
       String q_quadrant=getQuadrant(xq,yq);
       return "Point p is at "+p_quadrant+" and Point q is at "+q_quadrant;  
   }

   /* Method to get the quadrant of each passed point*/
   public String getQuadrant(double x, double y){
       if(x==0 && y==0){
           return "Origin";
       }
       else if(x==0){
           return "Y-axis";
       }
       else if(y==0){
           return "X-axis";
       }
       if (x >= 0) {
   return (y >= 0 ? "1st Quadrant":"4th Quadrant");
       } else {
return (y >= 0 ? "2nd Quadrant":"3rd Quadrant");
   }

   }
   /* Method to get the euclidean distance between p and q */
   public double euclidean(double xp, double yp, double xq, double yq){
   double euc_distance = 0.0;

   double x_square=Math.pow((xq-xp), 2);
   double y_square=Math.pow((yq-yp), 2);
   euc_distance= Math.sqrt(x_square+y_square);

   return euc_distance;
   }

   /* Method to calculate the slope */
   public double slope(double xp, double yp, double xq, double yq){

       double x_diff= xp-xq;
       double slope=0.0;

       /* Check applied to avoid a divide by zero error */
       if(x_diff == 0){
           System.out.println("Slope is undefined");
           System.exit(1);  
       }
       else{
           slope=(yp-yq)/x_diff;
       }
       return slope;  
   }


   public static void main (String[] args) throws java.lang.Exception
   {

   /* Creating an object of Points and calling each method individually and printing the value*/
   Points p = new Points();
   double euc=p.euclidean(2.3, 5.6,0.5,9);
   String quad=p.quadrant(0, -5.6,0,0);
   double slop=p.slope(0,0.5,0.6,9);
   System.out.print("Euclidean:"+euc+"\n Quadrant:"+quad+"\n Slope:"+slop);
   }
}

I can't figure out why my scanner isn't working; I'm not getting errors either. My job is to ask the user for INPUTS for all the points. Really I am stuck and this is due in a few hours, and also I'm using the latest eclipse with new JDK. New to programming and this site XD.

When I run the program my I get this as a result; I'm not getting any errors either Euclidean:3.847076812334269 Quadrant:Point p is at Y-axis and Point q is at Origin Slope:14.166666666666668

Michael
  • 945
  • 8
  • 27
  • 2
    *my scanner isn't working* doesn't describe your problem in the slightest. – shmosel Mar 17 '16 at 01:51
  • You need to give a clear description of 'whats not working', including expected output and any errors / where the errors are occurring in the code. – pczeus Mar 17 '16 at 01:51
  • Possible duplicate of [Skipping nextLine() after using next(), nextInt() or other nextFoo() methods](http://stackoverflow.com/questions/13102045/skipping-nextline-after-using-next-nextint-or-other-nextfoo-methods) – OneCricketeer Mar 17 '16 at 02:02
  • 1
    You only need one Scanner object. Plus, you don't even use the additional ones anyways. – OneCricketeer Mar 17 '16 at 02:04

1 Answers1

0

You need to update your prompts and get rid of unnecessary Scanners to fix the problem. Your prompts all ask for the "first" value, and keyboard1 -keyboard3 are never used. This code works just as well:

Scanner keyboard= new Scanner(System.in);
    System.out.print("Enter the first value for Xp: ");
    xp = keyboard.nextDouble();
    System.out.print("Enter the first value for Yp: ");
    yp = keyboard.nextDouble();
    System.out.print("Enter the first value for Xq: ");
    xq = keyboard.nextDouble();
    System.out.print("Enter the first value for Yq: ");
    yq = keyboard.nextDouble();
    String p_quadrant=getQuadrant(xp,yp);
    String q_quadrant=getQuadrant(xq,yq);
    return "Point p is at "+p_quadrant+" and Point q is at "+q_quadrant;
}

Also, in your main method, instead of creating a Point() object you create a Points() object. It does give me an error.

Patrick S.
  • 245
  • 1
  • 3
  • 15
  • Now i'm getting an error on class point it says "The type point is already defined." – MrYOLOYOYo Mar 17 '16 at 02:12
  • nvm its working but my my result is wrong now; the scanner is working but now my values are not being used. Enter the first value for Xp: 20 Enter the first value for Yp: 21 Enter the first value for Xq: 36 Enter the first value for Yq: 23 Euclidean:3.847076812334269 Quadrant:Point p is at 1st Quadrant and Point q is at 1st Quadrant Slope:14.166666666666668 – MrYOLOYOYo Mar 17 '16 at 02:16
  • I'm not quite sure what you're getting at. you need to explain what output you are expecting and be more clear about the problem. What I can see with your above code is this: Your getQuadrant() method is composed of a series of if() statements. The numbers you entered are all greater than 1, therefore the code that gets executed is the if() statement on lines 38-40. That is why you are getting "Quadrant 1" in return for your values. Beyond that, you will need to give more detail about what you are trying to accomplish. Hope that helps. Good luck. – Patrick S. Mar 17 '16 at 02:40