This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Boolean Help Needed in J2SDK1.4.2_06! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Boolean Help Needed in J2SDK1.4.2_06!" Watch "Boolean Help Needed in J2SDK1.4.2_06!" New topic
Author

Boolean Help Needed in J2SDK1.4.2_06!

Hugh Mclaughlin
Greenhorn

Joined: Nov 18, 2004
Posts: 24
Right basically I'm creating a program to ascertain whether the 3 sides of a triangle A,B,C input by the user make an Isosceles, Equilateral or Scalene triangle!

I've made a class and an app but am having disticnt trouble with the boolean operators! Please help me ASAP as I have to hand this in for uni tomorrow, if someone manages it I may reward you via Paypal!!

Heres my code:

class TriangleRecognition {

//-------------------FIELDS----------------------

private int a_value, b_value, c_value;

//-------------------CONSTRUCTORS----------------

public TriangleRecognition(int a_intInput, int b_intInput, int c_intInput) {
a_value = a_intInput;
b_value = b_intInput;
c_value = c_intInput;
}

//------------------METHODS----------------------

/* Resolve whether triangle is Equilateral, Isosceles or Scalene. */

public boolean resolveTriangleRecognition() {

if ((a_value) == (b_value) == (c_value)) ;
return(true);
if ((a_value) == (b_value) != (c_value)) ;
return(true);
if ((a_value) != (b_value) != (c_value)) ;
return(true);

}
}



-----------------------------------------------------------------------
import java.io.*;

class TriangleRecognitionApp {

//---------------FIELDS----------------

// Create BufferedReader class instance

public static BufferedReader keyboardInput =
new BufferedReader(new InputStreamReader(System.in));
private Triangle

//--------------METHODS-----------------

/* Main method */

public static void main(String[] args) throws IOException {
int newA_value, newB_value, newC_value;


//INPUT

System.out.print("Input side A:");
newA_value = new Integer.parseInt(keyboardInput.readLine());

System.out.print("Input side B:");
newB_value = new Integer.parseInt(keyboardInput.readLine());

System.out.print("Input side C:");
newC_value = new Integer.parseInt(keyboardInput.readLine());


//OUTPUT

if ((newA_value) == (newB_value) == (newC_value)) {
triangle = "Equilateral";
} else if ((newA_value) == (newB_value) != (newC_value)) {
triangle = "Isoceles";
} else if ((newA_value) != (newB_value) != (newC_value)) {
triangle = "Scalene";
} else {
triangle = "Error";
}
System.out.println("Equilateral");
System.out.println("Isosceles");
System.out.println("Scalene");
}
}


-----------------------------------------------------------------------


Please help ASAP!!!
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
All of the comparison operators (==, !=, >, ...) are binary operators, meaning they operate on two arguments only. To compare more than two arguments, you need to use the logical operatores "and" ("&&") and "or" ("||") .

Here's one example to get you going.The second line is just to show you how the compiler sees it. The comparison operators have higher precedence than the logical operators, meaning the parenthesis in that line are unnecessary, but they sometimes make it clearer for anyone reading the code.

In your first if testdoesn't work because the compiler turns the first part "(a_value) == (b_value)" into a boolean result which cannot be compared to b_value, an int.

[ Smily Attack! ]
[ November 18, 2004: Message edited by: David Harkness ]
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
now, about that paypal...


I've heard it takes forever to grow a woman from the ground
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Boolean Help Needed in J2SDK1.4.2_06!