• 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 problem (Boolean & Int)

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my java method I have the following:
public int nextFloorUp() // with no-arg constructor
{
if (floorcur >= 0 && floorcur <=3) / Note: last floor is 4
{
floorcur += 1;
return floorcur;
}
else
{
if (isdooropen == false &&) (floorcur >= 1 && floorcur <=3)))
// re above line: Compiler says "illegal start of expression"
floorcur += 1;
System.out.print("Method: Door is now closed and current floor ");
System.out.println(increased by 1 " + floorcur);
}
// I know I am mixing up "Boolean and Int", but why is the above line
(re: above line) wrong.
I even tried to use (!(is dooropen)) instead of "isdooropen == false
and it didn't work either.

What should I do to correct this?
Thanks for all your answers.
Charles.

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Charles,
Welcome to Java Ranch!
if (isdooropen == false &&) (floorcur >= 1 && floorcur <=3)))\

This line is missing some parenthes, and that first "&&" is in the wrong place; I'd rewrite this line as
if (isdooropen == false && floorcur >= 1 && floorcur <=3)
I see a bunch of other typos in this code -- missing quotes, s single / instead of a double // for a comment, and other stuff; not sure if this is a cut-and-paste or if those are transcription errors.
 
Charles Keller
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest,
I thank you for your answer re. Boolean code. I followed your advice and i have now written a new program:
class booleanTrial2
{
public static void main (String [] args)
{
boolean isdooropen = true;
if (isdooropen == true;
System.out.println(isdooropen); // no + needed
System.out.println("above statement result of (isdooropen == true)");
isdooropen = false;
if (!(isdooropen))
System.out.println(isdooropen);
System.out.println("above statement result of (isdooropen == false)");
}
}
/* It prints alright, or could I have done in a different way?
Now another question: Why are java programs sometimes segregated as
"source file" and "program file (with the *.class files total 4)
and sometimes only 1 program (Source and program together: total 1 .source and 1 .class file?
Thank you very much for your help.
Charles.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic