Concept explainers
In Java
The following is a java code for an old word puzzle: “Name a common word, besides tremendous,
stupendous and horrendous, that ends in dous.” If you think about this for a while, it will probably
come to you. However, we can also solve this puzzle by reading a text file of English words and
outputting the word if it contains “dous” at the end. The text file “words.txt” contains 87314
English words, including the word that completes the puzzle. This file is available on Moodle.
Your job is to insert try-catch statement in the below code, such that you surround the “risky” API
with an appropriate exception handler --Edit the code if you have to!
// import IO and util packages.
public class WordPuzzle
{
public static void main(String[] args)
{
String s;
Scanner scanner = new Scanner(Paths.get("words.txt"));
while (scanner.hasNext())
{
String word = scanner.next();
if (word.endsWith("dous"))
System.out.println(word);
} // end while
} // end main
} // end class
Step by stepSolved in 3 steps with 1 images
- Can someone please help me with this project for my Java Programming class? If you could correct my mistakes for me that would be great.arrow_forwardComplete in JAVA!arrow_forwardWrite in Java Prompt the user for a string that contains two strings separated by a comma. Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allenarrow_forward
- For Java Write code for an if-else block that checks separates integers into the following categories: An integer less than 0, An integer greater than 0 and less than or equal to 10, An integer greater than 10 that is even, and an integer greater than 10 that is odd. Have each category print out a different statement. What are some ways you can make your code more efficient when using if-else blocks?arrow_forwardIn java, without Arrays and using only String methods ( don't use String builder) // Question 17: In MS-DOS, a file name consists of up // to 8 characters (excluding '.', ':', backslask, '?', // and '*'), followed by an optional dot ('.' character) // and extension. The extension may contain zero to three // characters. For example, 1STFILE.TXT is a valid filename. // Filenames are case-blind. // // Write and test a method that takes // in a String, validates it as a valid MS-DOS file // name, appends the extensions ".TXT" if no extension // is given (that is, no '.' appears in FILENAME), converts // the name to uppercase, and returns the resulting string // to the calling method // If fileName ends with a dot, remove that dot and do not // append the default extension. If the name is invalid, // validFileName should return null. public String validFileName(String n) { }arrow_forwardIn Java for zybooks ,Lab 3.27, Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input. Output the login name, which is made up of the first six letters of the first name, followed by the first letter of the last name, an underscore (_), and then the last digit of the number (use the % operator). If the first name has less than six letters, then use all letters of the first name.arrow_forward
- In Java The following is a java code for an old word puzzle: “Name a common word, besides tremendous,stupendous and horrendous, that ends in dous.” If you think about this for a while, it will probablycome to you. However, we can also solve this puzzle by reading a text file of English words andoutputting the word if it contains “dous” at the end. The text file “words.txt” contains 87314English words, including the word that completes the puzzle. This file is available on Moodle.Your job is to insert try-catch statement in the below code, such that you surround the “risky” APIwith an appropriate exception handler --Edit the code if you have to!// import IO and util packages.public class WordPuzzle{public static void main(String[] args){String s;Scanner scanner = new Scanner(Paths.get("words.txt"));while (scanner.hasNext()) { String word = scanner.next(); if (word.endsWith("dous")) System.out.println(word); } // end while} // end main} // end classarrow_forwardWrite a FULL Java procedural program for a simple word guessing game. Below is an example of the required program behaviour. The bold text is user keyboard input. The player is allowed to guess one letter or the whole word incorrectly up to 5 times; each incorrect guess is called a “strike”. The program starts by displaying one full stop (’.’) for each character of the secret word. You may assume the word is hardcoded into the game, is in lower case, and is of length greater than one. In each round of the game, the game first checks if the player has reached the maxinum number of strikes; if so, the player loses and the game ends. If not, the game prints an input prompt. The player then guesses either one letter (by entering a single character) or the whole word (by entering multiple characters). If a single letter is guessed correctly, meaning the character occurs in the word, the game reveals the positions of those occurrences in the word and proceeds to the next round. If the whole…arrow_forwardWrite a java program that has the following 3 methods in addition to the main program. The main program should be interactive using a "do while loop". All input/out must be done in the main. 1. countLetter: Write a method, countLetter(...), that takes as parameter a sentence and letter and count how many times did the letter appear in the sentence. In the main the sentence are read from a file which contains many sentences and letters. Input file This is an example i The output of your program should be one of the following sentence 0 It is a palindrome or it is not a palindrome marrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education