• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Boolean value

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing a code for an assignment that has me use multiple methods in the main. The first method prints out a banner. The second method returns a string. In the second method, I'm meant to populate a string variable named productsCatalog with three different items of length 10. If the item is less than 10 letters we are meant to pad those items with spaces and then returns that string. The third method takes the string returned from the previous method and asks the user to enter an item to see if that item exists in the productsCatalog. If the items do exist in the productsCatalog then its meant to return true if not false. The first two methods in code work fine but the third only ask for the item from the user and then terminates and doesn't check if the item exists. Should I not use an if statement? Or is the problem elsewhere?

 
Ranch Hand
Posts: 270
15
Android Angular Framework Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Irvin:

You should take a look at the logic for the third function.  You seem to be expecting it to do a lot, but not giving it any relevant code to do so.  To get you going, you should:
1. Review == and the "equals(Object o)" method in Java.
2. Consider: how could the method ever return anything other than "true"?  You have the default at true, and then you never change the value to anything else.
3. Review some of the methods in java.lang.String.

I hope that helps.
reply
    Bookmark Topic Watch Topic
  • New Topic