Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// I WANT THE OUTPUT IN THE DIALOG BOX // SAMPLE: // E OCCURED 10 TIMES // O OCCURED 4 TIMES // G OCCURED 98

// I WANT THE OUTPUT IN THE DIALOG BOX

// SAMPLE:

// E OCCURED 10 TIMES

// O OCCURED 4 TIMES

// G OCCURED 98 TIMES

// E O G

// I NEED HELP PLEASE

1 import java.io.FileReader; 2 import javax.swing.JOptionPane; 3 4 public class Sonnet18 5 6 { 7 8 public static void main(String args[]) throws Exception 9 10 { 11 12 FileReader gr = new FileReader("Sonnet #18.txt"); 13 14 int i, al = 97; 15 16 char ref[] = new char[26]; 17 18 for (int g = 0; g < 25; ++g, al++) 19 20 ref[g] = (char) al; 21 22 int counter[] = new int[26]; 23 24 for (int j = 0; j < 26; ++j) 25 26 { 27 28 counter[j] = 0; 29 30 } 31 32 while ((i = gr.read()) != -1) 33 34 { 35 36 char sym = (char) i; 37 38 System.out.print(sym); 39 40 //check each and every character 41 42 switch (sym) 43 44 { 45 case 'a': 46 47 counter[0]++; 48 49 break; 50 51 case 'b': 52 53 counter[1]++; 54 55 break; 56 57 case 'c': 58 59 counter[2]++; 60 61 break; 62 63 case 'd': 64 65 counter[3]++; 66 67 break; 68 69 case 'e': 70 71 counter[4]++; 72 73 break; 74 75 case 'f': 76 77 counter[5]++; 78 79 break; 80 81 case 'g': 82 83 counter[6]++; 84 85 break; 86 87 case 'h': 88 89 counter[7]++; 90 91 break; 92 93 case 'i': 94 95 counter[8]++; 96 97 break; 98 99 case 'j': 100 101 counter[9]++; 102 103 break; 104 105 case 'k': 106 107 counter[10]++; 108 109 break; 110 111 case 'l': 112 113 counter[11]++; 114 115 break; 116 117 case 'm': 118 119 counter[12]++; 120 121 break; 122 123 case 'n': 124 125 counter[13]++; 126 127 break; 128 129 case 'o': 130 131 counter[14]++; 132 133 break; 134 135 case 'p': 136 137 counter[15]++; 138 139 break; 140 141 case 'q': 142 143 counter[16]++; 144 145 break; 146 147 case 'r': 148 149 counter[17]++; 150 151 break; 152 153 case 's': 154 155 counter[18]++; 156 157 break; 158 159 case 't': 160 161 counter[19]++; 162 163 break; 164 165 case 'u': 166 167 counter[20]++; 168 169 break; 170 171 case 'v': 172 173 counter[21]++; 174 175 break; 176 177 case 'w': 178 179 counter[22]++; 180 181 break; 182 183 case 'x': 184 185 counter[23]++; 186 187 break; 188 189 case 'y': 190 191 counter[24]++; 192 193 break; 194 195 case 'z': 196 197 counter[25]++; 198 199 break; 200 201 } 202 203 } 204 205 //sort the array to count top 11 frequencies 206 207 int temp = 0; 208 209 char t; 210 211 for (int c = 0; c < 26; c++) 212 213 { 214 215 for (int j = 1; j < (26 - c); j++) 216 217 { 218 219 if (counter[j - 1] < counter[j]) 220 221 { 222 223 temp = counter[j - 1]; 224 225 t = ref[j - 1]; 226 227 counter[j - 1] = counter[j]; 228 229 ref[j - 1] = ref[j]; 230 231 counter[j] = temp; 232 233 ref[j] = t; 234 235 236 } 237 238 } 239 240 } 241 242 243 //the required output mentioned in question 244 245 for (int j = 0; j < 10; ++j) 246 247 { 248 249 //String ref[j] = " " + ref[j] + " occured " + counter[j] + " times " ; 250 251 // JOptionPane.showMessageDialog(null, "The most frequent eleven letters are:" ); 252 253 //System.out.println(" "); 254 255 JOptionPane.showMessageDialog(null, ref[j] + " occured " + counter[j] + " times " ); 256 257 //System.exit(0); 258 259 JOptionPane.showMessageDialog( ref[j] ); 260 261 } 262 263 /* for (int j = 0; j < 10; ++j) 264 265 { 266 267 JOptionPane.showMessageDialog(null, ref[j] ); 268 269 }*/ 270 271 gr.close(); 272 273 } 274 275 } 276

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions

Question

Comment should this MNE have a global LGBT policy? Why/ why not?

Answered: 1 week ago