From dfd37cdade81f22ab7a54ce68077428bef723739 Mon Sep 17 00:00:00 2001 From: JPANZO Date: Mon, 7 Feb 2022 17:51:00 +0100 Subject: [PATCH] Productive-Code for CDPlayer-Method [Play] produced. --- src/main/java/device/cdPlayer/CDPlayer.java | 32 +++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/device/cdPlayer/CDPlayer.java b/src/main/java/device/cdPlayer/CDPlayer.java index ace5b17..12b241a 100644 --- a/src/main/java/device/cdPlayer/CDPlayer.java +++ b/src/main/java/device/cdPlayer/CDPlayer.java @@ -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; + } }