Homework 5 (Melody Maker & Image Algorithms) FAQ

Q: In Problem 1 (Melody Maker), why do I always get a NoSuchElementException when I try to read the input files? It seems to happen right after I read the first three parts (title, author, # of notes) when I try to read the rest of the lines of the file. What is going on?
A: Try inserting a call to nextLine on your Scanner right after reading the integer for the number of notes. The issue is that the Scanner's current "input cursor" position is still on the third line, at the end of the integer for # of notes, and hasn't dropped down to the next line yet where the notes will be found.
Q: In Problem 1 (Melody Maker), I get a NoSuchElementException after reading just 1 line! I read the first line (title) successfully, but then when I try to read the second line (author), it crashes. Why?
A: change new Scanner(filename) to new Scanner(new File(filename)) .
Q: In Problem 2 (Image Algorithms), when I say pixels[i][j], is i the x-coordinate or the y-coordinate?
A: 2-D arrays in Java are in "row-major" order. So [i] is the row and [j] is the column. Rows go downward and correspond to the y-coordinate; columns go sideways and correspond to the x-coordinate. So, perhaps counterintuitively, pixels[i][j] refers to a pixel whose x-coordinate is j and whose y-coordinate is i.
This document and its content are copyright © Marty Stepp, 2014. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.