Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-13-2008, 10:17 PM
Member
 
Join Date: Nov 2007
Location: Illinois
Posts: 12
jkswebsite has a little shameless behaviour in the past
Send a message via AIM to jkswebsite
Triangle
Quote:
* Write a class called Triangle.
*
* A triangle must have three int values for its side lengths.
* These private fields MUST have names a, b, and c.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* THE FOLLOWING METHODS AND CONSTRUCTORS MUST APPEAR IN THIS ORDER! *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Write a default constructor that creates an
* equilateral Triangle with side length 1.0
*
* Write another constructor that takes three int parameters that
* will be the three side lengths. It must validate
* the three parameters that they can actually form a triangle.
* (recall from Geometry: the sum of any two sides
* of a triangle must be greater than the third side)
* The constructor must throw an IllegalArgumentException
* if the parameters are invalid.
*
* Write a method called getLongestSide that takes no parameters
* and returns the value of the longest side length.
* (i.e. the greatest of a,b, and c)
*
* Write a method called isRightTriangle that takes no parameters
* and returns true if the Triangle, (whose sides are a,b, and c)
* form a right triangle and returns false otherwise.
* (hint: use Pythagorean Theorem and recall the longest side is the hypotenuse)
*
* Write a method called scalar that takes an int parameter and
* converts this Triangle to a similar Triangle by multiplying
* each side length by the parameter.
*
* ~~BONUS~~
* Write a method called isCongruentTo that takes a Triangle parameter
* and returns true if all three 'corresponding' sides are equal,
* and returns false otherwise.
* (example: 3,4,5 is congruent to 3,5,4 but not congruent to 3,3,5)
*
* ~~BONUS~~
* Write a method called area that returns the area of this Triangle
*
*/

... (over) ...

/**
* TriangleRunner should produce the following output shown below
*/

public class TriangleRunner {
public static void main(String args[]) {

Triangle t1 = new Triangle();
Triangle t2 = new Triangle(3,4,5);
Triangle t3 = new Triangle(4,6,3);
System.out.println(t1.longestSide());
System.out.println(t2.longestSide());
System.out.println(t3.longestSide());
System.out.println(t1.isRightTriangle());
System.out.println(t2.isRightTriangle());
System.out.println(t3.isRightTriangle());
t1.scalar(10);
t2.scalar(10);
t3.scalar(10);
System.out.println(t1.longestSide());
System.out.println(t2.longestSide());
System.out.println(t3.longestSide());
System.out.println(t1.isRightTriangle());
System.out.println(t2.isRightTriangle());
System.out.println(t3.isRightTriangle());
Triangle t4 = new Triangle(3,9,4);
}
}

/*
output:
1
5
6
false
true
false
10
50
60
false
true
false
Exception in thread "main" java.lang.IllegalArgumentException: cannot form a tri
angle with values 3,9,4
*/
That is out assignment, and I have a template and some basic starting code, but could someone walk me through it? My aim is Jkk088. I'll be on all day. Thanks so much, I really appreciate it.
__________________
Jonathan - AIM: JKK088
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-13-2008, 10:29 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 750
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
You've got pretty detailed instructions - there shouldn't be much confusion on your part, break out the old algebra/trig book and get started. I mean, you've even got a runner class that implies the output you're supposed to receive.. think about this for a second, how difficult can this be?

Btw, thanks for the message - but you're better off posting a thread such as you did here and chances are you'll get more responses, unless I was the only one you messaged. I'm not interested in doing other people's work, but I am interested in helping others learn the language. Your problem is not a Java problem, but a motivational problem. Why do you believe you can't do this?
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on July 13, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-13-2008, 10:33 PM
Member
 
Join Date: Nov 2007
Location: Illinois
Posts: 12
jkswebsite has a little shameless behaviour in the past
Send a message via AIM to jkswebsite
I don't really understand much java. I just need to hear what format to put it in..

(if statement..etc.)
__________________
Jonathan - AIM: JKK088

Last edited by jkswebsite : 01-14-2008 at 01:33 AM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-13-2008, 10:34 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 750
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Then start here.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on July 13, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-14-2008, 02:40 AM
Member
 
Join Date: Nov 2007
Location: Illinois
Posts: 12
jkswebsite has a little shameless behaviour in the past
Send a message via AIM to jkswebsite
this is the most recent code I have. I'M SO CLOSE!

Quote:
/**
* Class triangle
*/

public class Triangle {

private int a;
private int b;
private int c;

/**
* Default constructor that creates an equilateral Triangle with side length
* 1.0
*/

public Triangle() {
a = (int) 1;
b = (int) 1;
c = (int) 1;
}

/**
* Another constructor that takes three int parameters that will be the
* three side lengths. It must validate the three parameters that they can
* actually form a triangle. (recall from Geometry: the sum of any two sides
* of a triangle must be greater than the third side) The constructor must
* throw an IllegalArgumentException if the parameters are invalid.
* @return
*
* @return
*/

public Triangle(int d, int e, int f) {
if (d + e > f && e + f > d && f + e > d) {
a = d;
b = e;
c = f;
} else {
throw new IllegalArgumentException("cannot form a triangle with values "+ a +","+ b +","+ c);
}


}

/**
* Method called getLongestSide that takes no parameters and returns the
* value of the longest side length. (i.e. the greatest of a,b, and c)
*/

public int longestSide() {
if (a >= b && a >= c)
return a;
else if (b >= a && b >= c)
return b;
else
return c;
}

/**
* Method called isRightTriangle that takes no parameters and returns true
* if the Triangle, (whose sides are a,b, and c) form a right triangle and
* returns false otherwise. (hint: use Pythagorean Theorem and recall the
* longest side is the hypotenuse)
*/

public boolean isRightTriangle() {
if (a * a + b * b == c * c)
return true;
else
return false;
}

/**
* Method called scalar that takes an int parameter and converts this
* Triangle to a similar Triangle by multiplying each side length by the
* parameter.
*/

public void scalar(int i) {
a = a * i;
b = b * i;
c = c * i;
}

/**
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* BONUS! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
*/

{
/**
* Method called isCongruentTo that takes a Triangle parameter and
* returns true if all three 'corresponding' sides are equal, and
* returns false otherwise. (example: 3,4,5 is congruent to 3,5,4 but
* not congruent to 3,3,5)
*/

// INSERT CODE HERE
}

{
/**
* Write a method called area that returns the area of this Triangle
*/

// INSERT CODE HERE
}

}
this is the output I get:

Quote:
1
5
6
false
true
false
10
50
60
false
true
false

this is the output you're SUPPOSED to get:

Quote:
1
5
6
false
true
false
10
50
60
false
true
false
Exception in thread "main" java.lang.IllegalArgumentException: cannot form a tri
angle with values 3,9,4
Quote:
Triangle t4 = new Triangle(3,9,4);
the problem is my t4 in my TriangleRunner.java class isn't being read for some reason.

any ideas?
__________________
Jonathan - AIM: JKK088

Last edited by jkswebsite : 01-14-2008 at 03:15 AM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-14-2008, 03:55 AM
Member
 
Join Date: Nov 2007
Location: Illinois
Posts: 12
jkswebsite has a little shameless behaviour in the past
Send a message via AIM to jkswebsite
I Got It!!!! Thanks!!
__________________
Jonathan - AIM: JKK088
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-14-2008, 04:33 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 750
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
I haven't read over your final result, but I'll assume that you got it correct and are satisfied with your work. Congratulations on figuring it out and I hope that maybe you learned that this can be fun, if not now maybe you will in the near future. Aren't you glad you figured it? Deriving the solution for oneself is typically found to be more fun than acquiring the solution from someone else.

Cheers
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on July 13, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Computing the area of a triangle using Heron's Formula Java Tip java.lang 0 04-12-2008 09:39 PM
change the square to triangle java anotsu New To Java 2 02-06-2008 08:21 PM
Making triangle banie New To Java 4 02-02-2008 12:23 PM


All times are GMT +3. The time now is 04:26 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org