Question
**Question after TempFinder code* import java.io.*; import java.net.URL; import javax.swing.JOptionPane; /** * Class to find the temperature in a web page. * */ public class
**Question after TempFinder code*
import java.io.*; import java.net.URL;
import javax.swing.JOptionPane;
/** * Class to find the temperature in a web page. * */ public class TempFinder { /** * Method to find the temperature in the passed * file * @param fileName the name of the file to look in */ public String getTemp(String fileName) { String seq = "°"; String temp = null; String line = null; // try the following try { // read from the file BufferedReader reader = new BufferedReader(new FileReader(fileName)); // loop till end of file or find sequence while ((line = reader.readLine()) != null && line.indexOf(seq) < 0) {} // if there is a current line if (line != null) { // find the temperature int degreeIndex = line.indexOf(seq); int startIndex = line.lastIndexOf('>',degreeIndex); temp = line.substring(startIndex + 1, degreeIndex); } } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null,"Couldn't find file " + fileName); } catch (Exception ex) { JOptionPane.showMessageDialog(null,"Error during read or write"); ex.printStackTrace(); } return temp; } /** * Method to get the temperature from a network * @param urlStr the url as a string * @return the temperature as a string */ public String getTempFromNetwork(String urlStr) { String temp = null; String line = null; String seq = "°"; try { // create a url URL url = new URL(urlStr); // open a buffered reader on the url InputStream inStr = url.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inStr)); // loop till end of file or find sequence while ((line = reader.readLine()) != null && line.indexOf(seq) < 0) {} // if there is a current line if (line != null) { // find the temperature int degreeIndex = line.indexOf(seq); int startIndex = line.lastIndexOf('>',degreeIndex); temp = line.substring(startIndex + 1, degreeIndex); } } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null,"Couldn't connect to " + urlStr); } catch (Exception ex) { JOptionPane.showMessageDialog(null,"Error during read or write"); ex.printStackTrace(); } return temp; } public static void main(String[] args) { System.out.print("Reading current temp from stored Atlanta Journal file "); TempFinder finder = new TempFinder(); String temp = finder.getTemp("ajc-weather.html"); if (temp == null) System.out.println("Sorry, no temp was found in the file"); else System.out.println("The current temperature is " + temp); System.out.print(" Reading current temp from Bismarck Tribune "); String urlString = "http://www.bismarcktribune.com/"; temp = finder.getTempFromNetwork(urlString); if (temp == null) System.out.println("Sorry, no temp was found at " + urlString); else System.out.println("The current temp " + "from the network is " + temp); } }
*Use the TempFinder logic as a guide to create a new Java application that will check the spelling of a word using an online dictionary.
*You can use the following, along with the input word you are checking the spelling of, as the parameter for your URL object, or you can set up your own:
String urlStr = "http://www.dictionary.com/search?q=";
You will submit:
*All new/modified source code and a screen print of all execution results in a Word document
*Make sure you test a word that is spelled correctly and one that is spelled incorrectly
*comments that describe the functionality of all methods(s) you created for this assignment
*standard comments at the beginning of your program
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