| |
![]() |
|
Homework 09: Presidential Election 2016
For this assignment you need to write the program
Profile.java as detailed below. Assume you have a file with
names, representing votes (see below, make your own file for maximum satisfaction):
This is a short file so you can check by hand that calculations are correct.-bash-4.2$ ls -ld votes.txt -rw-r--r-- 1 dgerman faculty 304 Oct 18 01:56 votes.txt -bash-4.2$ cat votes.txt Bernie Trump Bernie Bernie Trump Trump Hillary Jeb! Hillary Trump Bernie Hillary Bernie Putin Putin Putin Hillary Bernie Hillary Hillary Hillary Trump Colbert Jeb! Jeb! Trump Johnson Stein Jeb! Jeb! -bash-4.2$
You have to write Note that your program can take one or two arguments:-bash-4.2$ javac Profile.java -bash-4.2$ java Profile votes.txt 3 1. Hillary=7 2. Bernie=6 3. Trump=6 -bash-4.2$ java Profile votes.txt 5 1. Hillary=7 2. Bernie=6 3. Trump=6 4. Jeb!=5 5. Putin=3 -bash-4.2$ java Profile votes.txt 1. Hillary=7 2. Bernie=6 3. Trump=6 4. Jeb!=5 5. Putin=3 6. Colbert=1 7. Johnson=1 8. Stein=1 -bash-4.2$
If the second argument is missing all words in the file are listed. Otherwise only as many words as the value of the second argument are being reported. Note that the output is sorted (by votes and alphabetically, Bernie beats Trump, and Colbert beats Johnson who beats Stein). Here's me using my program on other files: Let me know if you have any questions!-bash-4.2$ ls -ld seuss.txt -rw-r--r-- 1 dgerman faculty 1247 Oct 18 01:41 seuss.txt -bash-4.2$ cat seuss.txt here's an easy game to play here's an easy thing to say if a packet hits a pocket on a socket on a port and the bus is interrupted as a very last resort and the address of the memory makes your floppy disk abort then the socket packet pocket has an error to report if your cursor finds a menu item followed by a dash and the double-clicking icon puts your window in the trash and your data is corrupted 'cause the index doesn't hash then your situation's hopeless and your system's gonna crash you can't say this? what a shame sir! we'll find you another game sir! if the label on the cable on the table at your house says the network is connected to the button on your mouse but your packets want to tunnel on another protocol that's repeatedly rejected by the printer down the hall and your screen is all distorted by the side effects of gauss so your icons in the window are as wavy as a souse then you may as well reboot and go out with a bang 'cause as sure as I'm a poet the sucker's gonna hang! when the copy of your floppy's getting sloppy on the disk and the microcode instructions cause unnecessary risc then you have to flash your memory and you'll want to RAM your ROM quickly turn off the computer and be sure to tell your mom! -bash-4.2$ java Profile seuss.txt 5 1. the=21 2. your=15 3. a=11 4. and=10 5. to=8 -bash-4.2$ java Profile seuss.txt 10 1. the=21 2. your=15 3. a=11 4. and=10 5. to=8 6. on=7 7. as=6 8. is=4 9. then=4 10. you=4 -bash-4.2$ java Profile seuss.txt 1. the=21 2. your=15 3. a=11 4. and=10 5. to=8 6. on=7 7. as=6 8. is=4 9. then=4 10. you=4 11. an=3 12. by=3 13. if=3 14. of=3 15. 'cause=2 16. another=2 17. disk=2 18. easy=2 19. game=2 20. gonna=2 21. here's=2 22. in=2 23. memory=2 24. packet=2 25. pocket=2 26. say=2 27. sir!=2 28. socket=2 29. sure=2 30. want=2 31. window=2 32. I'm=1 33. RAM=1 34. ROM=1 35. abort=1 36. address=1 37. all=1 38. are=1 39. at=1 40. bang=1 41. be=1 42. bus=1 43. but=1 44. button=1 45. cable=1 46. can't=1 47. cause=1 48. computer=1 49. connected=1 50. copy=1 51. corrupted=1 52. crash=1 53. cursor=1 54. dash=1 55. data=1 56. distorted=1 57. doesn't=1 58. double-clicking=1 59. down=1 60. effects=1 61. error=1 62. find=1 63. finds=1 64. flash=1 65. floppy=1 66. floppy's=1 67. followed=1 68. gauss=1 69. getting=1 70. go=1 71. hall=1 72. hang!=1 73. has=1 74. hash=1 75. have=1 76. hits=1 77. hopeless=1 78. house=1 79. icon=1 80. icons=1 81. index=1 82. instructions=1 83. interrupted=1 84. item=1 85. label=1 86. last=1 87. makes=1 88. may=1 89. menu=1 90. microcode=1 91. mom!=1 92. mouse=1 93. network=1 94. off=1 95. out=1 96. packets=1 97. play=1 98. poet=1 99. port=1 100. printer=1 101. protocol=1 102. puts=1 103. quickly=1 104. reboot=1 105. rejected=1 106. repeatedly=1 107. report=1 108. resort=1 109. risc=1 110. says=1 111. screen=1 112. shame=1 113. side=1 114. situation's=1 115. sloppy=1 116. so=1 117. souse=1 118. sucker's=1 119. system's=1 120. table=1 121. tell=1 122. that's=1 123. thing=1 124. this?=1 125. trash=1 126. tunnel=1 127. turn=1 128. unnecessary=1 129. very=1 130. wavy=1 131. we'll=1 132. well=1 133. what=1 134. when=1 135. with=1 136. you'll=1 -bash-4.2$ Updated by © Adrian German for C212 -- 6W1 Summer 2019 |