Results 21 to 40 of 68
 11072010, 06:45 PM #21
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,290
 Blog Entries
 7
 Rep Power
 24
Darn, why did you ruin my lengthConstraint( ... ) method; I had hoped that you had continued my line of thoughts:
Java Code:for (int a= 1; a <= 20; a++) { for (int b= a; b <= 20; b++) { for (int c= b; c <= 20; c++) { // is the circumpherence <= 20? if (!lengthConstraint(a, b, c)) break; // is it a triangle? if (!triangleConstraint(a, b, c)) break; // the rest of the logic goes here ... } } }
kind regards,
Jos
 11072010, 06:46 PM #22Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
Argh! I just wrote a long reply and it didn't post!
I have removed the 'side' name on the sides because it was unnecessary and confusing. I thought I needed to declare the isValid boolean line to be able to use the code I use further down that prevents improperly formed triangles from being used...
(You call a lengthConstraint method, but I don't see code for it? Or a main method?)
...the lengthConstraint method was written as part of Jos' code to help me but I was confused by it and followed eclipse's suggestion for a 'TODO' line (something I am again unfamiliar with)
I thought I was starting to get somewhere but clearly i'm not... cry :(
 11072010, 06:56 PM #23Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
Back to the drawing board... does this look like a better starting point?
public class TriangleArea {
public static boolean areas (String[] args)
{
for (int a= 1; a <= 20; a++) {
for (int b= a; b <= 20; b++) {
for (int c= b; c <= 20; c++) {
// is the circumpherence <= 20?
if (!lengthConstraint(a, b, c)) break;
// is it a triangle?
if (!triangleConstraint(a, b, c)) break;
// the rest of the logic goes here ...
}
}
private static boolean lengthConstraint(int a, int b, int c) {
// TODO Autogenerated method stub
return false;
}
private static boolean triangleConstraint(int a, int b, int c) {
// TODO Autogenerated method stub
return false;
}
public static double area(double a, double b, double c){
double s = Math.sqrt( (a + b + c) / 2 ) ;
s = s * (s  a) * ( s  b ) * (s  c );
return s;Last edited by Atia of the julii; 11072010 at 07:03 PM.
 11072010, 07:12 PM #24Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
public class TriangleArea {
public static boolean areas (String[] args)
{
for (int a= 1; a <= 20; a++) {
for (int b= a; b <= 20; b++) {
for (int c= b; c <= 20; c++) {
// is the circumpherence <= 20?
if (!lengthConstraint(a, b, c)) break;
// is it a triangle?
if (!triangleConstraint(a, b, c)) break;
// the rest of the logic goes here ...
}
}
private static boolean lengthConstraint(int a, int b, int c) {
// TODO Autogenerated method stub
return false;
}
private static boolean triangleConstraint(int a, int b, int c) {
// TODO Autogenerated method stub
return false;
}
public static double area(double a, double b, double c){
double s = Math.sqrt( (a + b + c) / 2 ) ;
s = s * (s  a) * ( s  b ) * (s  c );
return s;
}
public void output ()
{
System.out.println ("[s]");
}
private double a;
private double b;
private double c;
private double area;
}
 11072010, 07:52 PM #25
Looks like you could benefit from going through all four links in Fubarable's signature.
db
 11072010, 07:53 PM #26
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,290
 Blog Entries
 7
 Rep Power
 24
My train of thoughts ran like this:
Java Code:for all values of a, b and c: if the length of the circumpherence isn't ok, skip the rest if a, b and c don't form a triangle, skip the rest do some interesting stuff with a, b and c
kind regards,
Jos
 11072010, 08:39 PM #27Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
public class TriangleArea {
{
for (int a= 1; a <= 20; a++) {
for (int b= a; b <= 20; b++) {
for (int c= b; c <= 20; c++) {
if a < b+c && b < a+c && c < a+b (a, b, c)) break;
public static double area(double a, double b, double c){
double s = Math.sqrt( (a + b + c) / 2 ) ;
s = s * (s  a) * ( s  b ) * (s  c );
return s;
}
}
I'm just not sure how to put it all together...
should the above look more like this now, to print the table would I need to include 4 separate System.out.println's at the end?!
I really do appreciate all of your help and I'm sorry I'm not proficient enough to make best use of your advice :(
 11072010, 08:47 PM #28
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,290
 Blog Entries
 7
 Rep Power
 24
You don't know basic Java syntax do you? Ok, this is going to take a while: try to define a small boolean method that, given three parameter values a, b and c, returns true if those values make up a triangle. The method is supposed to return false if those values don't form a valid triangle.
kind regards,
Jos
 11072010, 08:52 PM #29Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
Ok, thx, attempting now...
 11072010, 08:58 PM #30Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
The only way I can think to do this is to include an angle for the 3rd side? Or should I not be using angles at all? :S
public class Triangle {
double a, b, angle;
public Triangle( double a, double b, double angle) {
public boolean isValid() {
if ((a > 0 && b > 0) && (angle > 0 && angle <= 180)){
return true;
} else
return false;Last edited by Atia of the julii; 11072010 at 09:02 PM.
 11072010, 09:47 PM #31Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
Can anyone advise if i've done what Jos instructed me to do correctly please?

There's no need for angles here. You know that a triangle with lengths 1, 4, 6 is impossible because the two smaller sides added together are smaller than the largest size and so there would be no way to connect the two smaller sides if they're attached to the larger side.
So logically, we can say that if the two smaller sizes added together <what goes here?> the larger side, the triangle is valid.
 11072010, 10:34 PM #33Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
if (a+b) < c return true
(not sure if i've written that out correctly... i'm sure you're used to me saying that by now)
public class Triangle {
double a, b, c;
public Triangle( double a, double b, double c) {
public boolean isValid() {
if ((a+b) < (c)){
return true;
} else
return false;
 11072010, 10:44 PM #34Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
Fuba,
Can you tell me if I am getting anywhere with this?
public class TriangleArea {
public static void main( String[] args )
{
int a;
int b;
int c;
boolean state;
if ((a+b) < (c)){
state = true;
state = false;
}
{
for (a= 1; a <= 20; a++) {
for (b= a; b <= 20; b++) {
for ( c= b; c <= 20; c++) {}
if ((a < b+c) && (b < a+c) && (c < a+b (a, b, c))) break;}
}
public static double area(double a, double b, double c){
double s = Math.sqrt( (a + b + c) / 2 ) ;
s = s * (s  a) * ( s  b ) * (s  c );
return s;
}
}
 11072010, 10:59 PM #35Member
 Join Date
 Nov 2010
 Posts
 15
 Rep Power
 0
this kind of code will make you confused:
if ( a+ b <= c){
if (b + c <= a){
if (a + c <= b){
return false;
}else{
returnable = true;}}
else {
returnable = true;
}
you can use this: & means and
if ( (a+ b <= c) & (b + c <= a) & (a + c <= b) )
{returnable = false;}
else
{returnable = true;}
return returnable;
sry i didnt know how to use code tags
Java Code:testing :D
 11072010, 11:00 PM #36Senior Member
 Join Date
 May 2010
 Posts
 436
 Rep Power
 7
 11072010, 11:15 PM #37Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
Thankyou Doomsword, all constructive criticism is appreciated!
So you can use this: & means and
if ( (a+ b <= c) & (b + c <= a) & (a + c <= b) )
{returnable = false;}
else
{returnable = true;}
return returnable;
Is that to determine if it is a triangle? I'm sure curmudgeon you will find it pathetic that i'm asking that but i'm completely new to all of this and I haven't studied maths in over 10years.
 11072010, 11:19 PM #38Senior Member
 Join Date
 May 2010
 Posts
 436
 Rep Power
 7
Again this has nothing to do being pathetic or with studying math and only requires a simple thought experiment. If you have a stick that is 10 inches long and make it the base of your triangle, and you attach a 2 inch stick to the base's left and a 4 inch stick to the right of the base, attach them so they can swivel, can the two shorter sticks ever meet to form a triangle? If not, what is the requirement for the two shorter sticks to meet? Draw this out if it still doesn't make sense.
 11072010, 11:29 PM #39Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
Java Code:public class TriangleArea { public static void main( String[] args ) {} boolean isTriangle (double a, double b, double c) { if ( a < 0 && b < 0 && c < 0) return false; else return true; } int a; int b; int c; boolean returnable;{ if ( (a+ b <= c) & (b + c <= a) & (a + c <= b) ) {returnable = false;} else {returnable = true;} { for (a= 1; a <= 20; a++) { for (b= a; b <= 20; b++) { for ( c= b; c <= 20; c++) {} if ((a < b+c) && (b < a+c) && (c < a+b)) break; else; continue; } public static double area(double a, double b, double c){ double s = Math.sqrt( (a + b + c) / 2 ) ; s = s * (s  a) * ( s  b ) * (s  c ); return s; } }
Curmudgeon, I understand that 4+2=6 and the base is 10 so the total of the nonbase sides would have to equal 10 for it to be a triangle. Am i now using correct code for this in my code above?
I am sorry if i snapped, I have been doing this for a long time and i'm just pissed off with everything now.
:)
 11072010, 11:37 PM #40Member
 Join Date
 Nov 2010
 Posts
 87
 Rep Power
 0
Sorry I meant to post this as updated code...
Java Code:public class TriangleArea { public static void main( String[] args ) {} int a; int b; int c; boolean isTriangle;{ if ( (a+ b <= c) & (b + c <= a) & (a + c <= b) ) {isTriangle = true;} else {isTriangle = false;} { for (a= 1; a <= 20; a++) { for (b= a; b <= 20; b++) { for ( c= b; c <= 20; c++) {} if ((a < b+c) && (b < a+c) && (c < a+b)) break; else; continue; } public static double area(double a, double b, double c){ double s = Math.sqrt( (a + b + c) / 2 ) ; s = s * (s  a) * ( s  b ) * (s  c ); return s; } }
Similar Threads

JavaEntwickler (m/w) im schönen Freiburg gesucht (Firmenwagen, Laptop, iPhone inkl.)
By simon.erhardt in forum Jobs OfferedReplies: 0Last Post: 08112010, 08:19 AM 
Laptop Help
By Lil_Aziz1 in forum Forum LobbyReplies: 9Last Post: 08082010, 05:04 PM 
Access Macaddress on laptop
By dhaivat in forum AWT / SwingReplies: 0Last Post: 07112010, 02:49 PM 
AWT: Painting buttons and text areas in a canvas
By chappa in forum AWT / SwingReplies: 6Last Post: 01092010, 03:37 PM 
text areas, printstream, and "\n"
By diggitydoggz in forum New To JavaReplies: 10Last Post: 12262008, 05:03 PM
Bookmarks