Advertisement
Guest User

Untitled

a guest
May 24th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. General reminders:
  2.  
  3. Your name and assignment within the fir st 4 lines of source code in each file.
  4. Include ALL files for the project to run.
  5. Your name and assignment should show in GUI or console when the program runs.
  6. Use the specified file/class names for the project. If you need more classes, that's okay.
  7. If you use JFileChooser: leave it opening in user.home directory! That is, with the no-arg constructor -- not JFileChooser(".") If you want to speed up your debugging, feel free to pre-load the text box with something like
  8. "C:\\users\\...\\mytestdata.txt"
  9. Please don't use any "package" statements!
  10. You will submit FilesAreFun.java
  11.  
  12. It will use JFileChooser to allow the user to choose a file to copy.
  13.  
  14. If the user selects Cancel, the program should display "Ok, if you say so." and stop using System.exit(1).
  15.  
  16.  
  17.  
  18. Now use JFileChooser.showSaveDialog to allow the user to select a file to write.
  19.  
  20. If the user cancels, the program should display "No output, eh?" and stop using a System.exit(2)
  21.  
  22. If the file exists, you should warn the user, and allow the user to select a different file name if they want, or write over the existing file if they want.
  23.  
  24. (Hint: use File and the .exists() boolean method)
  25.  
  26.  
  27.  
  28. If the user selects an output file, you should copy the file from the input to the output , line by line. However, each input line should be preceded by a line number.
  29.  
  30. For example, if the input file looks like:
  31.  
  32. ***********************************************
  33.  
  34. john
  35. mildred
  36. fred
  37. ralph t. iguana
  38. tammerlane
  39. Gengis
  40. Attila
  41.  
  42. ***********************************************
  43.  
  44. the output file should look like:
  45.  
  46. ***********************************************
  47.  
  48. 1: john
  49. 2: mildred
  50. 3: fred
  51. 4: ralph t. iguana
  52. 5: tammerlane
  53. 6: Gengis
  54. 7: Attila
  55.  
  56. ***********************************************
  57.  
  58. When your program completes, it should display a message like:
  59.  
  60. "Done, successfully copied 7 lines."
  61.  
  62.  
  63.  
  64.  
  65.  
  66. Extra credit opportunity: format the line number as four digit numbers so things line up nicely if there are more than 10 lines in the file:
  67.  
  68. ***********************************************
  69.  
  70. 0001: john
  71. 0002: mildred
  72. 0003: fred
  73. 0004: ralph t. iguana
  74. 0005: tammerlane
  75. 0006: Gengis
  76. 0007: Attila
  77.  
  78. ***********************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement