Please code in Java way and the instruction of the code is in
the picture that has the assignment in it.
Output Docs Assignment Grade More 1 point Status: Not Submitted Write a print100 method that prints out the first 10 words of the dictionary array Write a method printStartsWith(String) that prints out the words that start with a string of letters in the dictionary array. Your method should take a parameter for the firstLetters as a String. You could use the Java String startsWith() method here if you'd like to, or use indexOf() to see if the firstLetters is at index 0 of the string. Write a spellcheck() method that takes a word as a parameter and returns true if it is in the dictionary array. It should return false if it is not found. Test your code by changing the word sent to the spellcheck() method in main. This algorithm is called a linear search where we step through the array one element at a time (here the dictionary one word at a time) looking for a certain element. Make at least one of your methods a for each loop
Sandbox My Section Practice New + u dictionary.txt Tester.java Spellchecker.java Spell Checker Submit + Continue Save 1. import java.util.Scanner; 2 public class Tester 3- { 4 public static void main(String[] args) 5- { 6 Scanner scan = new Scanner(System.in); 7 Spell Checker checker = new Spell Checker(); 8 checker.print100); System.out.println(); 10 //checker.printStartsWith("aby"); 11 System.out.println(); 12 - /*System.out.print("Enter a word to spell check or q to quit 13 String word = scan.nextLine(); 14 while (!word.equals("")) 15 { 16 if (checker.spellcheck(word) true) 17 System.out.println(word + " is spelled correctly!"); 18 else 19 System.out.println(word + " is misspelled!"); 20 21 System.out.print("Enter a word to spell check or q to qu 22 word = scan.nextLine(); 23 } 24 */ 25 scan.close(); 26 } 27 } 99BA5²AAARRA - Array 61 6.2 6.3 6.4 6.5
Sandbox My Section Practice New + dictionary.txt Tester.java Spellchecker.jaya Spell Checker Submit + Continue Save 1. import java.io. BufferedReader; 2 import java.io.FileReader; 3 import java.io.IOException; 4 import java.util.ArrayList; 5 import java.util.List; 6 7 public class Spell Checker 8 - { 9 private String[] dictionary; 10 11 // WRITE Your Methods HERE! 12 public void print100) 13 { 14 15 } 16 17 public void printStartsWith(String start) 18 - { 19 20 21 } 22 23 24 public boolean spellcheck(String target) 25 { 26 27 return false; 28 } 29 30 31 32 33 - public Spellchecker() { 34 try 35 - { Array 6.1 6.2 6.3 6.4 6.5 MacBook Air
PE Sandbox My Section Practice Newt Spell Checker Submit + Continue Save OL RI dictionary.txt Tester.java Spellchecker.java Conn Conn public Spell Checker() { try I { dictionary - readLines("dictionary.txt"); } catch(IOException e) { // Print out the exception that occurred System.out.println("Unable to access "+e.getMessage); } } 31 32 33 - 34 35- 36 37 38 39 40 41 42 43 44 45 46 47 - 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 public static String[] readLines(String filename) throws IOExc { FileReader fileReader = new FileReader(filename); BufferedReader bufferedReader = new BufferedReader(fileReade List<String> lines = new ArrayList<String>(); String line = null; while ((line = bufferedReader.readLine() != null) { lines.add(line); } bufferedReader.close(); return lines.toArray(new String[lines.size)); } } Array 6.2 6. 6.4 6.5 MacBook Air
Please code in Java way and the instruction of the code is in the picture that has the assignment in it.
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am