Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 7th, 2012, 04:52 PM
mightycow mightycow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2009
Posts: 6 mightycow Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 14 m 14 sec
Reputation Power: 0
Constructor problem among other things

Hey guys,

I have a few problems with the code I have been developing for my assignment. For starts I had to create two constructors to test string and integer parameters in my junit test cases all in the construction of a triangle.

The integer constructor calls a validate method and that works fine in my test. However, when I test for the triangles area I get an error message I think my constructor is the problem.

The second problem I'm having is with my setside# methods how do I call them? Could someone show me an example of a test case I could write.
I will include all my code and just a sample of my test cases. Thank you


[/CODE]

Reply With Quote
  #2  
Old April 7th, 2012, 05:03 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,961 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 3 h 23 m 31 sec
Reputation Power: 345
Quote:
I get an error message

Please post the full text of the error message.

Can you explain what the setSide# methods are each supposed to do? Have you looked at their code to see what the code in the methods do?
It looks like you call them with an int value. For example: setSide(1234);

Reply With Quote
  #3  
Old April 7th, 2012, 05:18 PM
mightycow mightycow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2009
Posts: 6 mightycow Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 14 m 14 sec
Reputation Power: 0
Hi, thanks for your reply. The error for the area test is: Triangle.TriangleException: valid triangle

I think it is incorrectly searching in the validate method when I should be finding the area from my setside# methods.

This I how Ive been trying to test them methods.

Code:
public void test04Area() throws Exception {
		

		Triangle t = new Triangle(0,0,0);
		//this area is correct
		t.setside1(50);
		t.setside2(50);
		t.setside3(50);
		
		assertEquals(t.getside1(),50);
		assertEquals(t.getside1(),50);
		assertEquals(t.getside3(),50);
		
	}


Thats where Im having problems with the constructor because it looks for 3 ints.

Reply With Quote
  #4  
Old April 7th, 2012, 05:37 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,961 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 3 h 23 m 31 sec
Reputation Power: 345
What line in the source causes the error message?

That's a strange error message: valid triangle
If its valid, why the error?

Reply With Quote
  #5  
Old April 7th, 2012, 05:46 PM
mightycow mightycow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2009
Posts: 6 mightycow Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 14 m 14 sec
Reputation Power: 0
Code:
if (side1 + side2 >= side3 && side2 + side3 >= side1 && side1 + side3 >= side2 && 
				side1 > 0 && side2 > 0 && side3 > 0 && side1 < 500 && side2 < 500 && side3 <500){
			throw new TriangleException("valid triangle");


I think this is the offending code. I just want to throw an exception for pretty much everything in my program including the valid stuff, for the time being at least. So do you think you can help?

Reply With Quote
  #6  
Old April 7th, 2012, 05:59 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,961 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 3 h 23 m 31 sec
Reputation Power: 345
Why should the code throw an exception for valid values?
Remove the throw statement so the code does not throw an exception if the values are good.

Quote:
I just want to throw an exception for pretty much everything

Why? That makes no sense to me. You should throw exceptions when something exceptional happens. Not for good data.

Reply With Quote
  #7  
Old April 7th, 2012, 06:21 PM
mightycow mightycow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2009
Posts: 6 mightycow Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 14 m 14 sec
Reputation Power: 0
Thanks a million that actually solved the problem I am getting the area fine now. Are my setside### methods relevant as I dont call them when getting the area the validate method seems to take care of that?
Could I rewrite my validate method to throw individual errors for each side, rather than invalid triangle. I know that means more code but it seems it is a requirement of the assignment.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Constructor problem among other things

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap