• Post Reply Bookmark Topic Watch Topic
  • New Topic

trying to work out how to make this equation work using booleans and integers?  RSS feed

 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello i have a problem i cannot seem to work out for the life of me.



i am basically trying to find out if this...: y ≥ y and a+3 ≠ 2        <<<<<<<<<<<<... equation is true or false by using the format above
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//error on this part where a+3 is<<<<

Please copy the full text of the error message and paste it here. It has important info about the error.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

... and just as a side question ... what should the sum of true and 3 equal to?

Henry
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
//error on this part where a+3 is<<<<

Please copy the full text of the error message and paste it here. It has important info about the error.


it is just highlighted in red at that point saying the operator + is undefined for the argument boolean,int. However still to this, even though i know 3 is not equal to true, surely theres a way to make it say false by keeping both values in the equation?
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
operator + is undefined for the argument boolean,int

Do you understand what the compiler is saying?  For example you can't add 3 to a boolean value like  true. The + operator requires two numeric operands.
boolean operands use boolean operators like AND and OR.
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
operator + is undefined for the argument boolean,int

Do you understand what the compiler is saying?  For example you can't add 3 to a boolean value like  true. The + operator requires two numeric operands.
boolean operands use boolean operators like AND and OR.


I totally understand what you are saying my friend and I knew this already however my question is now; how do I get this equation to work still or is there another way it can be done to show if it's true or false
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do I get this equation to work

Can you post the equation?
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
how do I get this equation to work

Can you post the equation?


y ≥ y and a+3 ≠ 2  
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
how do I get this equation to work

Can you post the equation?


This is the equation below

y ≥ y and a+3 ≠ 2  
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you describe in English what you are trying to do here?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
orry kaplan wrote:
I totally understand what you are saying my friend and I knew this already however my question is now; how do I get this equation to work still or is there another way it can be done to show if it's true or false


Well, please define the meaning of "work".  We don't have a meaning of what a sum of a boolean and int is supposed to result in. Now, obviously, you do.  So, if you tell us what the answer is supposed to be, then I guess we can help you get that equation into a format that Java understands. 

Henry
 
Carey Brown
Bartender
Posts: 3011
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
orry kaplan wrote:
Norm Radder wrote:
how do I get this equation to work

Can you post the equation?


This is the equation below

y ≥ y and a+3 ≠ 2  

In which case 'a' must be a numeric type.
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
orry kaplan wrote:
I totally understand what you are saying my friend and I knew this already however my question is now; how do I get this equation to work still or is there another way it can be done to show if it's true or false


Well, please define the meaning of "work".  We don't have a meaning of what a sum of a boolean and int is supposed to result in. Now, obviously, you do.  So, if you tell us what the answer is supposed to be, then I guess we can help you get that equation into a format that Java understands. 

Henry


I thought there is a way to show that this equation is false (becuSe you can't add an integer to the Boolean) however it's getting Java to show this is false without the need of errors
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is the equation below

y ≥ y and a+3 ≠ 2 

Change the definition of a to a numeric type to make that a legal java statement.
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:
orry kaplan wrote:
Norm Radder wrote:
how do I get this equation to work

Can you post the equation?


This is the equation below

y ≥ y and a+3 ≠ 2  

In which case 'a' must be a numeric type.


Well as you can see above a is given to me as a=false rather than a integer value
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:

This is the equation below

y ≥ y and a+3 ≠ 2 

Change the definition of a to a numeric type to make that a legal java statement.


How can I change a Boolean to a numeric value thought? Surely not possible
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did this problem come from?
Why do you think that it can be written in the java language?
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Where did this problem come from?
Why do you think that it can be written in the java language?


It's from a past paper from a couple of years ago from some uni work and I'm revising them but this one I encountered this problem however my lecturer said there should be a way to do it :/
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my lecturer said there should be a way to do it 

I guess you need to ask him this:
what is the value of true + 3
or false + 3


what does the value in a represent?  Is there an English description for it?  Using single letters for variable names is a poor practice.
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
my lecturer said there should be a way to do it 

I guess you need to ask him this:
what is the value of true + 3
or false + 3


That's the thing he won't tell me, so by what you're saying this equation I gave cannot be done?
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the value in the variable a represent?  Is there an English description for it? 

BTW Using single letters for variable names is a poor practice.
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:What does the value in the variable a represent?  Is there an English description for it? 

BTW Using single letters for variable names is a poor practice.


Well i thought i might as well put the whole first mock question up as its easier to understand this way. Now you can see this is literally all the information i have to go with :/

3.2 Relational operators

Create a new project and Java class called CS1702_Lab3. Add the following code:



Run the program. It should display the message “a is NOT less than b”. Test the program on a number of different values of a and b such that both parts of the if statement is run. Now add a similar set of program code that tests if a is greater than b.

Using the above code “snippet” as a basis, write a set of Java if statements that determines if the following statements are true, note that you must declare the variables first and choose the correct type.

Let x = 100, y = 204, z = -23.1, a = true, b = false, c = -204

1) x < y
2) x > z and a = b
3) 2c > y
4) x = b
5) c ≠ y or c = y
6) z ≠ y and c = a
7) y ≥ y and a+3 ≠ 2
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is part of the test recognizing that the expression is invalid?

Is it possible the person that entered the questions mistyped them?

What about this:
note that you must declare the variables first and choose the correct type
 
Julian West
Ranch Hand
Posts: 91
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The syntax on line 5 is incorrect and it does not reflect " y ≥ y and a+3 ≠ 2  ".

One way to go about it is to write them as separate conditionals and then turn that into a compound conditional.  Rewrite it; don't copy/paste/move text.
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Is part of the test recognizing that the expression is invalid?

Is it possible the person that entered the questions mistyped them?

What about this:
note that you must declare the variables first and choose the correct type


defo not mistyped. As said by my lecturer, they can be done which is so confusing
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Julian West wrote:The syntax on line 5 is incorrect and it does not reflect " y ≥ y and a+3 ≠ 2  ".

One way to go about it is to write them as separate conditionals and then turn that into a compound conditional.  Rewrite it; don't copy/paste/move text.


care to elaborate a bit more? im a little confused with how to go about this?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
orry kaplan wrote:
defo not mistyped. As said by my lecturer, they can be done which is so confusing


Don't know how to convince you... Unlike other languages like C, you simply can't add a boolean to an integer. Perhaps, in the future, Java will add this capability. In the meantime, I highly recommend that you get some more clarification on the assignment from your instructor.

Henry
 
Julian West
Ranch Hand
Posts: 91
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
orry kaplan wrote:
care to elaborate a bit more? im a little confused with how to go about this?


What does  if ((y >= y) && (a + 3 != 2) == 2)  say in English?  Read it as if it is the first time you've seen it.
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a+3 ≠ 2 could be rewritten as  a ≠ -1
Still not a valid java expression
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!