Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. package edu.wit.cs.comp1050;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * PA3c Driver Class   
  7.  * @author caushie
  8.  * 02/14/2019
  9.  */
  10. public class PA3c {
  11.    
  12.     /**
  13.      * Error to display if the command-line arguments are invalid
  14.      */
  15.     public static final String ERR_USAGE = "Please supply 2 numbers (x y).";
  16.    
  17.     /**
  18.      * Computes the distance using three methods
  19.      * from the origin to a point supplied via
  20.      * command-line arguments
  21.      *
  22.      * @param args command-line args: x y
  23.      */
  24.     public static void main(String[] args) {
  25.        
  26.         // replace the following line
  27.         // with whatever code you see fit
  28.         // in order to validate command-line
  29.         // arguments and, if valid, construct
  30.         // p via the two doubles supplied
  31.        
  32.         double x=0,y=0;
  33.         if (args.length!=2) {
  34.             System.out.println(ERR_USAGE);
  35.             System.exit(0);
  36.         }
  37.         try {
  38.             x=Double.parseDouble(args[0]);
  39.             y=Double.parseDouble(args[1]);
  40.            
  41.         } catch (NumberFormatException nfe) {
  42.             System.out.println(ERR_USAGE);
  43.             System.exit(0);
  44.         }
  45.         catch(NullPointerException e) {
  46.             System.out.println(ERR_USAGE);
  47.             System.exit(0);
  48.         }
  49.        
  50.        
  51.         final Point2D p = new Point2D(x,y);
  52.        
  53.         //////////////////////////////////////
  54.         // !! DO NOT CHANGE THE LINES BELOW !!
  55.         //
  56.         // They assume p has been
  57.         // properly constructed and perform
  58.         // all necessary output for the
  59.         // program
  60.         //////////////////////////////////////
  61.         final Point2D o = new Point2D();
  62.         System.out.printf("Point 1: %s%n", o);
  63.         System.out.printf("Point 2: %s%n", p);
  64.         System.out.printf("Static method distance: %.3f%n", Point2D.distance(o, p));
  65.         System.out.printf("Distance from P1: %.3f%n", o.distanceTo(p));
  66.         System.out.printf("Distance from P2: %.3f%n", p.distanceTo(o));
  67.     }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement