Thomas Banks

Greenhorn
+ Follow
since Apr 03, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Thomas Banks

Well spotted Martin. I have made the changes. Thank you
12 years ago
What I have done is create two Triangle constructors, one which will take string parameters (two many/few parameters) and one that will take integers and calls the validate method(calculate triangle <=0,>500,s1 > s2 +s3 ect).
I don't know if that's good practice(probably not?) but since the assignment is about writing my test cases first and then writing product code to make them pass I'm not too bothered so long as they pass, and they do. This is also why I throw a valid triangle exception so my test can pass for 3 valid parameters. Basically, my lecturer whats all my test cases to pass!

The very first problem I had when I started this thread (non-integer exception) is now working 100% with the string split method so thanks for that.

I still have a problem, in calling the validate method in my integer constructor I seem to upset the sides I have initialized to calculate the area. Is there something I could do to make them work in harmony?
This is what my constructor looks like and the area and validation tests that get in each others way.



Oh and I limited it because I didn't want big ridiculous triangles.

12 years ago
I have amended the code in my constructor to the way you recommended and I my valid and invalid triangle integer tests are passing. I also wrote some code to calculate the area
of the triangle and it worked but after creating the if statement to throw the exceptions (valid and invalid triangle) it no longer worked. How would I get my area test to pass again?
Since I enforced the invariant's for a triangle in the constructor what good are my setxxx methods and how should I re-write them?

Also, the validate method will still take string parameters how can I call that method from my constructor or any other method for that matter and also how would I create a test case if the triangle is now of integer type.
I have included all my product code and some of my tests. I have made a go at the validate method and tried to use the string split method but i think its not fully correct yet.

Thanks for your help



12 years ago
Thank you for them steps.
My lecturer however, does not want us to edit his code (skeleton code with empty methods that compiles but does nothing) in anyway.
The assignment is to show our knowledge of the software development process, write test cases first then get the tests to pass by writing our own product code.
The code I have shown is just one part of the assignment as I have to get the area and do individual tests on the 3 sides. I will post the skeleton code below so you know what I am talking about.

He did include the string tokenizer class so I assume he wanted us to use it but I was not familiar with it at all, someone recommended I use the scanner class instead.
Is there fundamental problems with my code? Other than the fact I cant throw an exception if a string is entered because it has taken me quite a bit of time to get this far.

thanks

12 years ago
The program I am creating is part of a college assignment.
My lecturer wants the numbers inputted as a string separated by a comma for reasons unknown, probably to make it 10 times tougher.
12 years ago
This is my full code. To be honest I'm not sure if the parameters are being read into the sides of the array myself but it seems to be working.
There is Comparison failure coming up and I think the two test are confusing each other. I have included that other test case which I suppose to find no integers.





And a picture paints a thousand words so I have attached one.
Thanks
12 years ago
hello guys,

I'm trying to throw an exception when the program receives a non integer parameters. ie. a string
I have looked at many examples on the internet and have so far failed to come up with a working solution. My test case continually fails.
I am not overly familiar with the try/catch method but I think that would be the logical way to go about things, any help would be great thanks.



12 years ago
Thank you Sir I have realized the errors of my ways.
12 years ago
Hi thanks for your advice. I have modified my code and now it is throwing an exception in the correct manner.
However, I am now having difficultly in writing the product code to throw the correct exception.
I wish to throw an exception for "too many parameters" and "too few parameters" as we know a triangle should take 3 parameters.
This is what I have come up with so far. The code I thought would work is in my previous post.
Is it possible you could help me throw those two exceptions?

Thanks

12 years ago
Hi guys,

I'm relatively new to java and I am currently struggling to get my head around the scanner and throwing exceptions. I have written the
below code but every time I try running my test I get a failure message. Is it possible one of you guy could tell me where Im going wrong?
Thank you.




12 years ago