Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: About java program. Date: Sun, 16 Jun 2013 17:28:11 +0200 Lines: 52 Message-ID: References: <324f929f-772e-4004-81e1-6b454cdae794@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net CVDy+STt0nHjLdx1z70TqgM7mWBBEVvYrD7BEyjW9EkrRbrdE= Cancel-Lock: sha1:ZaVga7C4weZw0K+nmUrmWD5VnzA= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: X-Antivirus: avast! (VPS 130616-0, 16.06.2013), Outbound message X-Antivirus-Status: Clean Xref: csiph.com comp.lang.java.programmer:24425 On 16.06.2013 15:21, lipska the kat wrote: > On 16/06/13 00:12, Robert Klemme wrote: >> On 15.06.2013 22:38, rajbhaumik@gmail.com wrote: >>> import acm.program.*; >>> public class askYesNoQuestion extends ConsoleProgram { >>> public void run(){ >>> String str=readLine("Would you like instructions"); >>> println(askYesNoquestion(str)); >>> } >>> 7. private boolean askYesNoquestion (String str){ >>> if(str.equals("yes"))return true; >>> if(str.equals("no")) return false; >>> } >>> >>> } >>> the false is that , the program cannot be executed, because no 7 >>> said, this method must return a type of boolean. >> > > One possible solution (not compiled or tested) > > private boolean askYesNoquestion (String str){ > boolean response = false; > if(str.equals("yes")){ > response = true; > } > return response; > } Why are you making it so complicated? Just do private static boolean isStringYes(String str) { return str.equals("yes"); } Or, for NPE safety: private static boolean isStringYes(String str) { return "yes".equals(str); } Btw, I also changed the name because the method did not ask a question at all. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/