Question
Write a program in Java which accepts an input text file containing words, saves it to an array, sorts the array according to the first
Write a program in Java which accepts an input text file containing words, saves it to an array, sorts the array according to the first letter and outputs to the standard output. In order to sort, you must use the Insertion Sort (no other type of sorting is permitted). It is assumed that words in the input text file are separated by commas. The name of the Java class must be StringSorter which implements the interface Sorter. The program must throw a RuntimeException if a word does not start with a letter, displaying the following message: Word found which does not start with a letter. To test if a character is a letter or not, you may use the method Character.isLetter().
you are not allowed to use any existing Java library and/or external packages for solving the problem.
Test input: University, Cat, Alex, Marble, Tampa
Expected output: Alex, Car, Marble, Tampa, University
Test input: Apple, 2017Mercedes, Car, New, Zebra
Expected output: An exception will be thrown with the message Word found which does not start with a letter.
4 Required Java code 1 public interface Sorter public void sortFileContent (String fileName); 1 public class StringSorter implements Sorter public void sortFileContent (String fileName) throws RuntimeException 4 // Implement this method // Do not forget to throw RuntimeException when // a word does not start with a letter 10 12 13 14 15 16 17 public static void main(String[] args) StringSorter fileSorter fileSorter.sortFileContent ("input.txt"); new StringSorterO
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started