Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions

Question

List and explain the goals of business communication.

Answered: 1 week ago