HW06 Solution (JAVA file)

HW06 Solution (JAVA file) - "...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 public class HW06 { public static void main(String args[]) throws Exception{ // SOLUTION TO TASK #2 java.io.File inFile = new java.io.File("input.txt") java.util.Scanner input = new java.util.Scanner(inFile) // Declare the arrays // Students may assume a fixed number of input records int MAX = 10 String[] title = new String[MAX] String[] bookYear = new String[MAX] String[] filmYear = new String[MAX] // Read the data from the input file System.out.println("Reading input file. ..") int size = 0 title[size] = input.nextLine() bookYear[size] = input.nextLine() filmYear[size] = input.nextLine() size++ } input.close() System.out.println("Finished reading input.") // SOLUTION TO TASK #3 java.io.File outFile = new java.io.File("table.html") java.io.PrintWriter output = new java.io.PrintWriter(outFile) // Create the beginning of the HTML file, including the table headings System.out.println("Writing output file.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ..") output.println("<html>") output.println(" <head><title>Harry Potter Books and Films</title></head>") output.println(" <body>") output.println(" <table border = \"1\">") output.println(" <th>Title</th><th>Book Year</th><th>Film Year</th>") // Write the data to the HTML file for (int j = 0 output.println(" <tr>") output.println(" <td>" + title[j] + "</td>") output.println(" <td>" + bookYear[j] + "</td>") output.println(" <td>" + filmYear[j] + "</td>") output.println(" </tr>") } output.println(" </table>\n </body>\n</html>") output.close() System.out.println("Finished writing output.") } } Sheet1 Page 2 // Allow for up to 10 records (NOT REQUIRED) // Title // Year the book was published // Year the film was released // Allow for less than 10 records (NOT REQUIRED) // Keep track of actual quantity of records (NOT REQUIRED) j < size j++) {...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

HW06 Solution (JAVA file) - "...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online