Cobrec

import javax.swing.*; import java.awt.*; import java.applet.*; //import java.text.*; public class RandomPoints1A extends JApplet { public static void main (String[] args){ //variables int getx,gety,xleft,yleft,xright,yright,xtop,ytop,xbot,ybot; double distance, totaldist=0, minimum, maximum; //creating the text area JTextArea mytextarea = new JTextArea(30,80); mytextarea.setLineWrap(true); mytextarea.setFont (new Font("Arial",Font.BOLD,18) ); JScrollPane scrollpane = new JScrollPane(mytextarea); //get user input on number of points String input = JOptionPane.showInputDialog(null,"Please input the number of points you would like to display...","Enter a number",JOptionPane.QUESTION_MESSAGE); int number=Integer.parseInt(input); //ask the user to determine the maximum size for x and y input = JOptionPane.showInputDialog(null,"What is the maximum value of 'X'","Max value of 'X'",JOptionPane.QUESTION_MESSAGE); int max_x = Integer.parseInt(input); input = JOptionPane.showInputDialog(null,"What is the maximum value of 'Y'","Max value of 'Y'",JOptionPane.QUESTION_MESSAGE); int max_y = Integer.parseInt(input); //ask the user if they want to see the data int answer = JOptionPane.showConfirmDialog(null,"Would you like to see the results?","User type", JOptionPane.YES_NO_OPTION); //creates the arrays based on user input int[]x=new int[number]; int[]y=new int[number]; xleft=max_x; yleft=0; xright=0; yright=0; ytop=max_y; xtop=0; xbot=0; ybot=0; minimum=(max_x+max_y); maximum =0; //loops to create a random number for each element of the x and y arrays for (int i=0; i<number; i++){ //generate random number for X getx = (int)(Math.random()*max_x); x[i] = getx; //generate random number for Y gety = (int)(Math.random()*max_y); y[i] = gety; //shows the random points generated if the user selects "yes" option if (answer == JOptionPane.YES_OPTION) { mytextarea.append("\nPoint #" + (i+1) + " is at coordinates " + "(" + x[i] + "," + y[i] + ")"); } //finds distances between points if (i > 0) { distance = Math.sqrt((Math.pow(x[i-1] - x[i], 2) + Math.pow(y[i-1] - y[i], 2))); //String num = "0.00#"; //DecimalFormat df = new DecimalFormat(num); //String pdistance = df.format(distance); //finds the sum of the distance between points totaldist = totaldist + distance; //finds minimum and maximum distances between points if (distance < minimum) minimum = distance; if (distance > maximum) maximum = distance; mytextarea.append("\nThe distance between point " + (i) + " and point " + (i+1) + " is " + distance + "\n"); } if (i == (number-1)) { mytextarea.append("\nThe minimum distance was " + minimum); mytextarea.append("\nThe maximum distance was " + maximum); mytextarea.append("\nThe sum of the distances is " + totaldist + "\n"); } //determines left most point if (x[i] < xleft) { xleft = x[i]; yleft = y[i]; } //determines right most point if (x[i] > xright) { xright = x[i]; yright = y[i]; } //determines top most point if (y[i] < ytop) { xtop = x[i]; ytop = y[i]; } //determines bottom most point if (y[i] > ybot) { xbot = x[i]; ybot = y[i]; } //displays text area if (i == (number-1)) { mytextarea.append("\nThe left most point is (" + xleft + "," + yleft + ")"); mytextarea.append("\nThe right most point is (" + xright + "," + yright + ")"); mytextarea.append("\nThe top most point is (" + xtop + "," + ytop + ")"); mytextarea.append("\nThe bottom most point is (" + xbot + "," + ybot + ")"); JOptionPane.showMessageDialog(null, scrollpane, "Random Points", JOptionPane.PLAIN_MESSAGE); //Sets up graphics GIVES ILLEGAL START OF Expression ERROR!!! //public void paint (Graphics g) { //g.setColor(color.BLUE); //g.drawLine(xleft,yleft,xbot,ybot); //g.drawLine(xbot,ybot,xtop,ytop); //g.drawLine(xtop,ytop,xright,yright); //} } } } }