/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package pointtest; import javax.swing.JFrame; import javax.swing.JOptionPane; import java.util.Scanner; import java.util.InputMismatchException; /** * * @author jcmtiernan */ public class PointTest { /** * @param args the command line arguments */ public static void main(String[] args) { final int POINT_ARRAY_LENGTH; Scanner myInput = new Scanner(System.in); int tempX = 0, tempY = 0; Point pt1 = new Point(); Point pt2 = new Point(3,4); Point pt6 = new Point(4); Point pt3 = new Point(5,5); Point pt4 = new Point(4,8); Point pt5 = new Point(9); POINT_ARRAY_LENGTH = 99; Point[] pt = new Point[POINT_ARRAY_LENGTH]; PlainRobot r2D2 = new PlainRobot(22, pt2); PlainRobot robbie = new PlainRobot(22, pt6); PlainRobot c3PO = new PlainRobot(22, pt1); SmallRobot wallE = new SmallRobot(138,pt3, 15, 10.0); TinyRobot T1000 = new TinyRobot( "Tea", 1000); PlainRobot johnny5 = new PlainRobot(); TinyRobot guiltySpark = new TinyRobot("gS"); wallE.setKindOfLoco(LOCOMOTION.ROLLERS); MovingThing roomba = new MovingThing(2,LOCOMOTION.WHEELS); MovingThing darryl = new MovingThing(13,"feet"); // String hW = new String("Hello World"); //JOptionPane.showMessageDialog(null, r2D2); System.out.println("The value of robbie is "+robbie); System.out.println("The value of wallE is "+wallE); System.out.println("The value of T1000 is "+T1000); System.out.println("The value of johnny5 is "+johnny5); System.out.println("The value of guiltySpark is "+guiltySpark); System.out.println("MovingThing roomba "+roomba); System.out.println("MovingThing darryl "+darryl); /* DrawSmiley panel = new DrawSmiley(); JFrame application = new JFrame(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); application.add( panel ); application.setSize( 250, 280 ); application.setVisible( true ); */ for (int i=0; i < 99; i++) { pt[i] = new Point(i%10,i%5); } System.out.println("The midterm in CSE1325 will be Tuesday March 24"); System.out.println("Please enter two values to be used as the x and y values of a point: "); boolean inputOK = false; while (!inputOK) { inputOK = true; try { tempX = myInput.nextInt(); } catch(InputMismatchException e) { myInput.nextLine(); inputOK = false; } try { if (inputOK) { tempY = myInput.nextInt(); } } catch(InputMismatchException e) { myInput.nextLine(); inputOK = false; } if (!inputOK) { System.out.println("Your inputs were not valid. Please enter two integer values: "); } } System.out.println("You entered x = "+tempX+" and y = "+tempY); pt[12].setX(tempX); pt[12].setY(tempY); System.out.println("The value of pt["+ 12 +"] is "+pt[12]); int i =0; for (Point p: pt) { System.out.println("The value of pt["+ (i++) +"] is "+p); } /* int[] vals = {0,1,2,3,4,5,6,7,8,9}; int i =0; for (Point p: pt) { try { int k = p.getX(); if (i == 14) { k = 42; } if (vals[k] < 10) // trying to demonstrate an error { System.out.println("The value of pt["+ (i++) +"] is "+p); } } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Wha-ha!"); i++; } } */ /* System.out.println("This is our "+1+"st program."); System.out.println("The value of pt1 is "+pt1); System.out.println("The value of pt2 is "+pt2); System.out.println("The value of pt6 is "+pt6); System.out.println("The value of pt6.x is "+pt6.getX()); */ //System.out.println("Pt6 "+pt6+" is "+pt6.getDistanceFromOrigin()+" units from the origin"); //pt6.setX(-419); // pt6.x = 19; //System.out.println("The value of pt6.x is "+pt6.getX()); //System.out.println("Pt6 "+pt6+" is "+pt6.getDistanceFromOrigin()+" units from the origin"); //System.out.println("Pt2 "+pt2+" is "+pt2.getDistanceFromOrigin()+" units from the origin"); } }