Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

i dont understand(((

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Bartender
Posts: 2846
150
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code tags ( <-- Its a link) to post your code. I have modified your post to include them. Doesn't it look better now ?

Can you share a bit about your question:
What is it that you don't understand in the above program ?
 
Andrey Chernov
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:Please use code tags ( <-- Its a link) to post your code. I have modified your post to include them. Doesn't it look better now ?

Can you share a bit about your question:
What is it that you don't understand in the above program ?


This code should ask "who to show?"
and when entering: room, giraffe, person, must show the characteristic
 
salvin francis
Bartender
Posts: 2846
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what happens when you compile it or run it ?
Hint1: One of your braces are at the wrong location. Hint 2: You are trying to use a variable before declaring it
 
Andrey Chernov
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:And what happens when you compile it or run it ?
Hint1: One of your braces are at the wrong location. Hint 2: You are trying to use a variable before declaring it



that's better?
 
Marshal
Posts: 72479
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Andrey Chernov wrote:. . . that's better?

Afraid, no. Your additional { is in the wrong place and the code is now so poorly indented that we can't see what is happening. Please try your code whenever you alter anything. Please put every } to the left of what precedes it, and don't write two braces on the same line. If you indent your code correctly, you will be able to see its structure for yourself. Then you will see where the errors are. A text editor that supports bracket matching may help; if you are using Windows®, I would recommend NotePad++.
 
salvin francis
Bartender
Posts: 2846
150
Google Web Toolkit Eclipse IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adding to what Campbell said...
Have a look at the code below. I have added some comments to help you understand better.
 
Andrey Chernov
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I did it!!!
 
Campbell Ritchie
Marshal
Posts: 72479
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still not at all good, I am afraid.
If you write "room".equals(n), there is no need for the null test. That code can be relied upon never to throw a null pointer exception. It is also not possible for the Scanner#nextLine() method to return null.
Names like java_lesson2, n, and p are not at all good, because nobody can tell what they mean by looking at them. Only use _s in names of constants. Write something like InputDemo, and start class names with CapitalLetters please.
Make all the fields private and initialise them via a constructor. Always write a constructor because otherwise the compiler will add a default constructor, which might not do what you want.
Please indent your code consistently; lines 15‑39 are too far to the left and lines 42‑55 are too far to the right. Please divide those long lines (47, 50, and 53) into several shorter lines; they are very difficult to read.
 
salvin francis
Bartender
Posts: 2846
150
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like now everything is just jammed into main method. We have a blog post about that. Main is Pain (<-- It's a link)
Your original idea of using methods looked better.

To make your code more user friendly, you could show a menu like this :

Next, if you are learning about objects and inheritance, your code could be as simple as:
Where "Printable" is your class.
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic