Question

need help to complete this java program // add appropriate import statements here. // These imports...

need help to complete this java program


// add appropriate import statements here.


// These imports you can leave as is.
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
@author yourAccountNameHere
*/

public class ConnectTheDots extends Application {
      
    /*
    * Do not add code to main(). Add it below in connectTheDots instead.
    */
    public static void main(String[] args) {
        launch(args);
    }
   
    /*
    * You do not have to change any of the code in this "start" method.
    */
    @Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Connect the Dots");
Group root = new Group();
Canvas canvas = new Canvas(1000, 840);
GraphicsContext gc = canvas.getGraphicsContext2D();
connectTheDots(gc);
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
  
/*
Put your data file reading method (described in Section 3) here
above the connectTheDots() method.
Use the method in Lab 9 as a guide.
*/
// TODO: method to do the File I/O. See Section 3 of the project handout
// for details about the method signature.
  

/*
* Pretend this is your main method. All of your code
* should go in here, including your array. Call methods as necessary.
* You will write one separate method to read from the data file.
*/
private void connectTheDots(GraphicsContext gc) {
    gc.setFill(Color.GREEN);
gc.setStroke(Color.BLUE);
gc.setLineWidth(5);
    final int DOT_DIAM = 8;
    final int MAX_DOTS = 500; // use this for the size of your Point array
   
    // here is where you will create your array,
    // and call your method to read in the data file.
   
   
    // examples of drawing (run the program as is to see them)
    // Use these as a guide for drawing your dots and lines.
   
    // draw a filled circle of DOT_DIAM diameter at (60,10)
    gc.fillOval(60, 10, DOT_DIAM, DOT_DIAM);
    // draw a line from (30,80) to (100,200)
    gc.strokeLine(30,80,100,200);
      
    }
}

program to read a series of coordinates from the data file coords.txt

coords.txt

567 210
600 184
627 204
579 173
571 146
564 193
582 253
681 360
737 410
768 522
734 457
748 542
732 442
779 549
785 585
756 670
752 658
664 771
678 741
624 807
577 839
543 840
684 835
875 842
624 846
742 868
788 860
663 871
550 859
630 857
544 877
625 877
304 873
463 882
345 892
260 864
130 876
329 860
228 847
109 860
327 848
215 834
90 838
259 829
164 818
30 810
280 829
380 847
473 840
553 833
619 786
553 855
434 843
504 821
653 732
620 743
689 693
600 725
523 722
596 714
525 751
483 746
583 739
469 770
515 766
441 807
461 782
435 792
490 799
401 795
414 778
393 834
311 824
344 812
359 781
293 808
369 790
297 819
227 816
186 785
206 786
155 734
209 771
145 744
292 782
375 765
515 615
520 665
528 596
565 545
584 544
578 567
597 559
542 536
506 461
482 475
475 440
440 447
421 431
450 419
405 400
333 178
322 188
316 163
202 112
197 140
219 168
217 138
218 185
239 203
245 173
251 204
278 198
279 175
314 213
309 187
305 225
318 243
328 216
316 268
332 296
346 438
361 423
395 416
336 452
359 462
411 423
348 478
390 488
438 461
413 490
445 504
469 488
438 518
469 521
497 506
454 542
483 554
509 531
473 569
506 576
530 549
494 595
510 606
489 603
408 696
406 723
404 680
386 668
459 577
382 658
378 628
436 555
361 643
354 612
426 522
339 626
336 597
380 506
356 505
348 548
401 503
316 628
298 600
313 524
291 617
240 637
227 613
335 482
223 597
223 550
324 465
214 555
222 511
323 432
212 507
224 466
325 397
202 470
209 440
315 373
202 436
211 405
325 341
200 405
198 380
320 313
191 369
203 345
309 293
190 344
190 324
298 272
181 324
190 298
301 241
177 301
190 272
281 224
169 276
169 253
262 226
154 248
155 224
237 214
146 223
148 202
213 206
137 190
140 170
196 169
133 157
139 133
186 140
144 121
145 103
223 114
101 94
99 121
126 122
80 124
101 146
120 137
77 156
92 183
117 178
62 196
76 227
120 219
63 245
61 281
98 287
126 258
68 315
98 343
124 335
142 287
103 360
121 382
162 314
117 393
137 395
166 353
125 420
146 428
176 386
136 443
148 462
191 427
144 478
159 492
196 458
146 508
164 516
196 495
150 534
167 548
199 523
151 569
167 581
205 591
156 595
182 616
204 590
172 632
201 651
213 631
200 665
235 679
265 639
231 689
267 678
290 636
263 695
309 671
327 638
302 692
336 681
342 655
314 730
363 730
376 687
358 750
435 718
560 567
530 498
414 395
300 145
188 98
327 140
318 121
383 188
456 360
518 435
585 498
632 488
610 509
642 461
576 450
605 470
561 461
644 450
621 400
597 382
597 393
531 293
504 339
526 321
495 389
526 283
499 207
494 222
511 148
563 92
613 82
654 98
677 137
667 178
677 200
660 180
661 212
647 183
621 188
658 250
681 266
693 257
676 233
670 163
617 137
628 129
630 194
682 164
685 128
756 103
749 132
770 130
735 174
735 199
704 242
689 278
645 301
667 323
694 311
667 301
705 310
710 291
688 293
726 284
723 268
700 271
743 263
729 250
718 253
754 240
745 225
719 233
765 219
758 207
733 215
784 199
777 184
750 190
796 171
781 156
749 167
797 144
782 136
761 148
800 112
738 118
981 88
964 122
926 122
941 135
814 155
981 131
974 159
809 180
979 172
958 200
794 208
965 214
930 233
786 225
922 241
874 266
770 249
865 279
815 301
753 279
816 317
780 334
731 301
774 345
737 351
708 325
743 363
708 361
678 341
713 375

0 0
Add a comment Improve this question Transcribed image text
Answer #1

java

package gui;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

//add appropriate import statements here.


//These imports you can leave as is.
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
@author yourAccountNameHere
*/

public class ConnectTheDots extends Application {

   /*
   * Do not add code to main(). Add it below in connectTheDots instead.
   */
   public static void main(String[] args) {
       launch(args);
   }

   /*
   * You do not have to change any of the code in this "start" method.
   */
   @Override
   public void start(Stage primaryStage) {
       primaryStage.setTitle("Connect the Dots");
       Group root = new Group();
       Canvas canvas = new Canvas(1000, 840);
       GraphicsContext gc = canvas.getGraphicsContext2D();
       connectTheDots(gc);
       root.getChildren().add(canvas);
       primaryStage.setScene(new Scene(root));
       primaryStage.show();
   }

   /*
Put your data file reading method (described in Section 3) here
above the connectTheDots() method.
Use the method in Lab 9 as a guide.
   */
   //TODO: method to do the File I/O. See Section 3 of the project handout
   //for details about the method signature.

   int readFile(int coords[][]){
       Scanner sc = new Scanner(System.in);
       File file = new File("coords.txt"); //reading data from this file
       Scanner reader;
       String line="";
       int index=0;
       try {
           //read file using scanner
           reader = new Scanner(file);
           while(reader.hasNextLine()){
               line = reader.nextLine();
               String xy[] = line.split(" ");
               coords[index][0] = Integer.parseInt(xy[0]);
               coords[index][1] = Integer.parseInt(xy[1]);
               index++;
           }
       } catch (FileNotFoundException e) {
           System.out.println("file not found");
       }
       sc.close();
       return index;
   }


   /*
   * Pretend this is your main method. All of your code
   * should go in here, including your array. Call methods as necessary.
   * You will write one separate method to read from the data file.
   */
   private void connectTheDots(GraphicsContext gc) {
       gc.setFill(Color.GREEN);
       gc.setStroke(Color.BLUE);
       gc.setLineWidth(5);
       final int DOT_DIAM = 8;
       final int MAX_DOTS = 500; // use this for the size of your Point array

       // here is where you will create your array,
       int dots[][] = new int[MAX_DOTS][2];
       int size=readFile(dots);
       // and call your method to read in the data file.
       gc.fillOval(dots[0][0], dots[0][1], DOT_DIAM, DOT_DIAM);
       for(int i=1;i<size;i++){
           // draw a filled circle of DOT_DIAM diameter at (60,10)
           gc.fillOval(dots[i][0], dots[i][1], DOT_DIAM, DOT_DIAM);
           // draw a line from (30,80) to (100,200)
           gc.strokeLine(dots[i-1][0], dots[i-1][1],dots[i][0], dots[i][1]);
       }
   }
}

coords.txt

567 210
600 184
627 204
579 173
571 146
564 193
582 253
681 360
737 410
768 522
734 457
748 542
732 442
779 549
785 585
756 670
752 658
664 771
678 741
624 807
577 839
543 840
684 835
875 842
624 846
742 868
788 860
663 871
550 859
630 857
544 877
625 877
304 873
463 882
345 892
260 864
130 876
329 860
228 847
109 860
327 848
215 834
90 838
259 829
164 818
30 810
280 829
380 847
473 840
553 833
619 786
553 855
434 843
504 821
653 732
620 743
689 693
600 725
523 722
596 714
525 751
483 746
583 739
469 770
515 766
441 807
461 782
435 792
490 799
401 795
414 778
393 834
311 824
344 812
359 781
293 808
369 790
297 819
227 816
186 785
206 786
155 734
209 771
145 744
292 782
375 765
515 615
520 665
528 596
565 545
584 544
578 567
597 559
542 536
506 461
482 475
475 440
440 447
421 431
450 419
405 400
333 178
322 188
316 163
202 112
197 140
219 168
217 138
218 185
239 203
245 173
251 204
278 198
279 175
314 213
309 187
305 225
318 243
328 216
316 268
332 296
346 438
361 423
395 416
336 452
359 462
411 423
348 478
390 488
438 461
413 490
445 504
469 488
438 518
469 521
497 506
454 542
483 554
509 531
473 569
506 576
530 549
494 595
510 606
489 603
408 696
406 723
404 680
386 668
459 577
382 658
378 628
436 555
361 643
354 612
426 522
339 626
336 597
380 506
356 505
348 548
401 503
316 628
298 600
313 524
291 617
240 637
227 613
335 482
223 597
223 550
324 465
214 555
222 511
323 432
212 507
224 466
325 397
202 470
209 440
315 373
202 436
211 405
325 341
200 405
198 380
320 313
191 369
203 345
309 293
190 344
190 324
298 272
181 324
190 298
301 241
177 301
190 272
281 224
169 276
169 253
262 226
154 248
155 224
237 214
146 223
148 202
213 206
137 190
140 170
196 169
133 157
139 133
186 140
144 121
145 103
223 114
101 94
99 121
126 122
80 124
101 146
120 137
77 156
92 183
117 178
62 196
76 227
120 219
63 245
61 281
98 287
126 258
68 315
98 343
124 335
142 287
103 360
121 382
162 314
117 393
137 395
166 353
125 420
146 428
176 386
136 443
148 462
191 427
144 478
159 492
196 458
146 508
164 516
196 495
150 534
167 548
199 523
151 569
167 581
205 591
156 595
182 616
204 590
172 632
201 651
213 631
200 665
235 679
265 639
231 689
267 678
290 636
263 695
309 671
327 638
302 692
336 681
342 655
314 730
363 730
376 687
358 750
435 718
560 567
530 498
414 395
300 145
188 98
327 140
318 121
383 188
456 360
518 435
585 498
632 488
610 509
642 461
576 450
605 470
561 461
644 450
621 400
597 382
597 393
531 293
504 339
526 321
495 389
526 283
499 207
494 222
511 148
563 92
613 82
654 98
677 137
667 178
677 200
660 180
661 212
647 183
621 188
658 250
681 266
693 257
676 233
670 163
617 137
628 129
630 194
682 164
685 128
756 103
749 132
770 130
735 174
735 199
704 242
689 278
645 301
667 323
694 311
667 301
705 310
710 291
688 293
726 284
723 268
700 271
743 263
729 250
718 253
754 240
745 225
719 233
765 219
758 207
733 215
784 199
777 184
750 190
796 171
781 156
749 167
797 144
782 136
761 148
800 112
738 118
981 88
964 122
926 122
941 135
814 155
981 131
974 159
809 180
979 172
958 200
794 208
965 214
930 233
786 225
922 241
874 266
770 249
865 279
815 301
753 279
816 317
780 334
731 301
774 345
737 351
708 325
743 363
708 361
678 341
713 375

output:

Add a comment
Know the answer?
Add Answer to:
need help to complete this java program // add appropriate import statements here. // These imports...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Bubba's Burgers - Statistics Question

    Sampled StoreDessert Orders Per 1,000 TransactionsStore 1185Store 2226Store 3290Store 4226Store 5255Store 6293Store 7138Store 8203Store 9276Store 10173Store 11275Store 12199Store 13213Store 14321Store 1597Store 16152Store 17319Store 18193Store 19126Store 20215Store 21186Store 22289Store 23181Store 24196Store 25183Store 2690Store 27178Store 28103Store 29173Store 30231Store 31158Store 32202Store 33234Store 34273Store 35218Store 36247Store 37223Store 38108Store 39238Store 40143Store 41206Store 42300Store 4389Store 44202Store 45250Store 46210Store 47137Store 48215Store 49204Store 50188Store 51255Store 52196Store 53123Store 54189Store 55206Store 56146Store 57136Store 58211Store 59164Store 60246Store 61324Store 62125Store 63195Store 64173Store 65179Store 6676Store 67248Store 68199Store 69223Store 70240Store 71224Store 72215Store 73222Store 74170Store...

  • In C++ Programming: Using a single for loop, output the even numbers between 2 and 1004...

    In C++ Programming: Using a single for loop, output the even numbers between 2 and 1004 (inclusive) that iterates (loops) exactly 502 times. The outputted numbers be aligned in a table with 10 numbers per row. Each column in the table should be 5 characters wide. Do not nest a loop inside of another loop. Hint: First create and test the code that output the numbers all on one line (the command line will automatically wrap the output to new...

  • 33 On May 6, Jim Ryan borrowed $14,000 from Lane Bank at 7 % interest. Jim...

    33 On May 6, Jim Ryan borrowed $14,000 from Lane Bank at 7 % interest. Jim plans to repay the loan on March 11. Assume the loan is on ordinary interest. How much will Jim repay on March 11? (Use Days in a year table) (Round your answer to the nearest cent.) Jm repay etbook 7-1 TABLE Exact days-in-a-year calendar (excluding leap year)" Day of month 30 31 30 31 28 31 30 31 31 30 31 31 Dec Mar...

  • We are interested in the relationship between the compensation of Chief Executive Officers (CEO) ...

    We are interested in the relationship between the compensation of Chief Executive Officers (CEO) of firms and the return on equity of their respective firm, using the dataset below. The variable salary shows the annual salary of a CEO in thousands of dollars, so that y = 150 indicates a salary of $150,000. Similarly, the variable ROE represents the average return on equity (ROE)for the CEO’s firm for the previous three years. A ROE of 20 indicates an average return...

  • Create a program that will use the attached input file and perform the following operations. Read...

    Create a program that will use the attached input file and perform the following operations. Read the file into an appropriate JCF data structure. Look up a (list of) names and numbers matching a last name or the first letters of a last name, ignoring case. Look up a (list of) names and numbers matching a number or the first digits of a number. Add a name and number to the list. Sort the list by first name, last name...

  • If the two signal handling functions in 3000pc were replaced by one function, would there be...

    If the two signal handling functions in 3000pc were replaced by one function, would there be any significant loss of functionality? Briefly explain /* 3000pc.c */ 2 3 4 5 6 7 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <unistd.h> 11 #include <sys/mman.h> 12 #include <errno.h> 13 #include <string.h> 14 #include <sys/types.h> 15 #include <sys/wait.h> 16 #include <semaphore.h> 17 #include <string.h> 18 #include <time.h> 19 20 #define QUEUESIZE 32 21 #define WORDSIZE 16 22 23 const int wordlist_size =...

  • HELP needed urgently....Data and question is attacted below..... Thank you in advance there is no data...

    HELP needed urgently....Data and question is attacted below..... Thank you in advance there is no data link fir this data it’s all in photos.... thank you i have already posted the question We were unable to transcribe this imageNo. 2 3 4 5 6 7 8 Working Sector Public Own Public Public Private Public Private Private Own Own Private Public Public Public Private 9 10 11 12 13 Public IS 16 17 18 19 20 21 22 23 24 25...

  • Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin...

    Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin at the University of Washington, Seattle, who originally wrote this assignment (for their CSE 142, in Java) This program focuses on classes and objects. Turn in two files named Birthday.cs and Date.cs. You will also need the support file Date.dll; it is contained in the starter project for this assignment. The assignment has two parts: a client program that uses Date objects, and a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT