Question: Hello! I need help with a problem from 'Objects First With Java 5th Edition'. Exercise 4.16 Rewrite both the listFile and removeFile methods in MusicOrganizer
Hello!
I need help with a problem from 'Objects First With Java 5th Edition'.
Exercise 4.16
"Rewrite both the listFile and removeFile methods in MusicOrganizer so that they use your validIndex method to check their parameter, instead of the current boolean expression. They should only call get or remove on the ArrayList if validIndex returns true."
My solution:
the validIndex method:
public boolean validIndex(int idx) { int lastIdx = files.size() -1; if(idx >= 0 && idx <= lastIdx) { return true; } else { return false; } } and the modified methods:
public void listFile(int index) { if(validIndex(index) == true) { String filename = files.get(index); System.out.println(filename); } } and
public void listFile(int index) { if(validIndex(index) == true) { String filename = files.get(index); System.out.println(filename); } } But my teacher answered with:
"In MusicOrganizer.java (v1) you should use your method validIndex instead of the boolean expression as it says in the exercise."
I don't understand what I should change? And how? What does he mean? I'm cofused...
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
