-
Boolean errors in Compiler!
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!!!
-
Well if i were you i wouldn't be using a boolean function ("it's offer 2 option");
at String function would do more good in your case i think
annway here's what i got for you
but you need to work on the rest of it
because i juste did it for the Equilateral case.
import java.io.*;
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))&&((a_value) == (c_value))&&((b_value==(c_value)))){
return(true);
}
else return(false);
}
public String checkitout(boolean a){
if(a==true){
return "Your triangle is Equilateral";
}
else return "Your triangle is not Equilateral";
}
}
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 {
TriangleRecognition tria=new TriangleRecognition(
Integer.parseInt(keyboardInput.readLine()),
Integer.parseInt(keyboardInput.readLine()),
Integer.parseInt(keyboardInput.readLine()));
System.out.println(tria.checkitout(tria.resolveTriangleRecognition()));
}
}
good luck
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|