Create a class hierarchy which has an abstract class called WordList (the same c
ID: 3813145 • Letter: C
Question
Create a class hierarchy which has an abstract class called WordList (the same class as in project 2 but it is abstract). This class should have two subclasses: UnsortedWordList and SortedWordList, each having a method called add. In the UnsortedWordList the method add will add to the end of the list (append), and in the SortedWordList it will do an insert. So now, rather than in project 2 where you used two of the same kind of list (WordList) you will use one unsorted list and one sorted list.
Create a new exception called IllegalWordException by extending lllegalArgumentException.
When you create a new Word from a String read from the input file, catch any exceptions thrown by the constructor and print the offending string to the console along with the message from the Exception. The constructor should check that the word is 3 characters, and all the characters are letters.
Add a File menu to your GUI which has menu items for Open and Quit. You should now be able to select an input file using the GUI.
Submitting the Project.
You should now have at least the following files to submit for this project:
Explanation / Answer
import java.io.*;
import java.util.*;
public class Task {
private BufferedReader input;
private PrintWriter output;
private StringTokenizer stoken;
String fin = "input";
String fout = "output";
private void solve() { // some solving code...
int n = nextInt();
int[] mas = new int[n];
for (int i = 0; i<n; i++){
mas[i] = nextInt();
}
}
Task() throws IOException {
input = new BufferedReader(new FileReader(fin + ".txt"));
output = new PrintWriter(new FileWriter(fout + ".txt"));
solve();
input.close();
output.flush();
output.close();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextFloat() {
return Float.parseFloat(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken()); }
String nextToken() {
while ((stoken == null) || (!stoken.hasMoreTokens())) {
try {
String line = input.readLine();
stoken = new StringTokenizer(line);
} catch (IOException e) {
e.printStackTrace();
}
}
return stoken.nextToken();
}
public static void main(String[] args) throws IOException {
new Task();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.