Problem:
Your cell phone rings. Return true if you should answer it. Normally you answer, except in the morning you only answer if it is your mom calling. In all cases, if you are asleep, you do not answer.
answerCell(false, false, false) → true
answerCell(false, false, true) → false
answerCell(true, false, false) → false
Solution:
public boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep) { if (isAsleep) return false; if ((isMorning && isMom) || !isMorning) return true; else return false; }
wrong code
ReplyDeleteit is actually correct, maybe you forgot to delete the beginning that they give you
Deletepublic boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep) {
ReplyDeleteif(!isAsleep) {
return isMom || !isMorning ? true : false;
}
return false;
}
public static void main(String[] args) {
ReplyDelete// TODO code application logic here
AnswerCell n=new AnswerCell();
System.out.println(n.answerCell(false,false,false)); //true
System.out.println(n.answerCell(false,false,true)); //false
System.out.println(n.answerCell(true,false,false)); //false
}
public boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep){
if (isAsleep)
{
return false;
}
if (!isMorning || isMom)
{
return true;
}
return false;
}
}
return (!isAsleep && !isMorning || (!isAsleep && isMom));
ReplyDeletepublic boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep) {
ReplyDeletereturn (!isAsleep && !isMorning || !isAsleep && isMom);
}
public boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep) {
ReplyDeletereturn (!isAsleep && !isMorning || !isAsleep && isMom);
}
if (!isAsleep) {
ReplyDeleteif (!isMom) {
if (!isMorning) {
return true;
}
return false;
}
return true;
}
return false;
public boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep) {
ReplyDeleteif (isAsleep){
return false;
}
else if (!isAsleep && isMorning && !isMom){
return false;
}else{
return true;
}
}
public boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep) {
ReplyDeleteif (isAsleep){
return false;
}
else if (!isAsleep && isMorning && !isMom){
return false;
}else{
return true;
}
}
public boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep) {
ReplyDeleteif(isAsleep){
return false;
}
if(isMorning){
return isMom;
}
return false;
}
public boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep) {
ReplyDeletereturn !isAsleep && (isMom || !isMorning);
}
return((isMorning&&isMom&&!isAsleep||!isMorning&&!isAsleep)?true:false);
ReplyDeleteif(isAsleep)return false;
ReplyDeleteif(!isMorning||isMom)return true;
else return false;