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 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
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
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.
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
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
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
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 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 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
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?
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
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
