|
|
@ -1,7 +1,7 @@ |
|
|
|
package device.cdPlayer; |
|
|
|
|
|
|
|
import device.Device; |
|
|
|
|
|
|
|
import device.cdPlayer.exceptions.*; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
@ -16,8 +16,6 @@ public class CDPlayer implements Device { |
|
|
|
|
|
|
|
private String actualPlayTrack=""; |
|
|
|
private CD loadedCD; |
|
|
|
private String[] cdAlbum=new String[]{}; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void louder() { |
|
|
@ -62,6 +60,19 @@ public class CDPlayer implements Device { |
|
|
|
|
|
|
|
@Override |
|
|
|
public String play() { |
|
|
|
if(isCdFlapOpen()){ |
|
|
|
throw new CdFlapIsOpenException(); |
|
|
|
} |
|
|
|
else if(!isCdFlapOpen()&&getCdDriveContent()==0){ |
|
|
|
throw new NoCDException(); |
|
|
|
} |
|
|
|
else if(!isCdFlapOpen()&&getCdDriveContent()==1&&!checkFormat(loadedCD.getFormat())){ |
|
|
|
throw new FormatNotSupportedException(); |
|
|
|
} |
|
|
|
else if(!isCdFlapOpen()&&getCdDriveContent()==1&&checkFormat(loadedCD.getFormat())){ |
|
|
|
System.out.println(loadedCD.getFormat()+" "+this.actualPlayTrack+" is playing."); |
|
|
|
return "AllConditionsForPlayMet"; |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
@ -79,5 +90,20 @@ public class CDPlayer implements Device { |
|
|
|
public void tapOnCdFlap(){ |
|
|
|
this.CdFlap+=1; |
|
|
|
} |
|
|
|
private boolean checkFormat(String format){ |
|
|
|
if(this.supportedFormats.contains(format)) |
|
|
|
return true; |
|
|
|
else return false; |
|
|
|
} |
|
|
|
private int getCdDriveContent() { |
|
|
|
return CdDriveContent; |
|
|
|
} |
|
|
|
private boolean isCdFlapOpen() { |
|
|
|
if(CdFlap==1) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
else |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
} |