• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

What should I change in this program

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have recently started learning classes and object and tried this simple code. here I want to print what rooms have more element so i have implemented if-else but when I try to compile, it is giving me error and I can't able to understand so what correction should I have to made



Error is can't find symbol (room1.Home>room2.Home)
 
Marshal
Posts: 72059
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Somebody has corrected the code tags in your post (you didn't quite get them right). Doesn't it look better Unfortunately your code isn't indented correctly, and that shows.

Where are you learning programming? Your object‑orientation is unfortunately not complete. Make all the fields private, and initialise them in the constructor. Give access to the fields with getXXX() methods. Don't calculate the sum of items in HomeTest; give Home a totalItems() or similar method, Use that to calculate and return the totals.

Your room objects don't have a member called Home, which is what the compiler is complaining about.
 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic