Question: Use the provided URLDissector.java as a starting point to create FractionReader.java . Instead of reading URL's, read fractions from the file fractions.txt , one per
Use the provided URLDissector.java as a starting point to create FractionReader.java. Instead of reading URL's, read fractions from the file fractions.txt, one per line, add them to an ArrayList, and print them in reverse order with their values.
Expected Output
110/50 = 2.2 99/98 = 1.010204081632653 1/5 = 0.2 7/8 = 0.875 2/3 = 0.6666666666666666 5/6 = 0.8333333333333334 21/7 = 3.0 3/4 = 0.75
Fraction.txt
3/4 21/7 5/6 2/3 7/8 1/5 99/98 110/50
//******************************************************************** // URLDissector.java Author: Lewis/Loftus // // Demonstrates the use of Scanner to read file input and parse it // using alternative delimiters. //********************************************************************
import java.util.Scanner; import java.io.*;
public class URLDissector { //----------------------------------------------------------------- // Reads urls from a file and prints their path components. //----------------------------------------------------------------- public static void main(String[] args) throws IOException { String url; Scanner fileScan, urlScan;
fileScan = new Scanner(new File("urls.inp"));
// Read and process each line of the file while (fileScan.hasNext()) { url = fileScan.nextLine(); System.out.println("URL: " + url);
urlScan = new Scanner(url); urlScan.useDelimiter("/");
// Print each part of the url while (urlScan.hasNext()) System.out.println(" " + urlScan.next());
System.out.println(); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
