私は新しいコンピュータープログラミングの学生です。Java と基本的な構成に関するビデオを見たところ、ビデオの人物がこのトピックに関する例を次のように作成しました。
public class PaperTray
{
int pages = 0;
....
public boolean isEmpty()
{
return pages > 0;
}
}
public class Printer extends Machine
{
private PaperTray paperTray = new PaperTray();
....
public void print(int copies)
{
....
while(copies > 0 && !paperTray.isEmpty() )
{
System.out.println("some text to print");
copies--;
}
if(paperTray.isEmpty())
{
System.out.println("load paper");
}
}
私の質問は、用紙トレイが空の場合、クラス PaperTray でメソッド isEmpty() が false を返すことです。したがって、Printer クラスの if ステートメントは実行されません。また、用紙トレイが空でない場合、PaperTray クラスの isEmpty() メソッドは true を返すため、Printer クラスの while ステートメントは実行されません。私が間違っているのでしょうか、それともビデオ クリップのインストラクターが何か間違いを犯したのでしょうか?
ありがとうございました