Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Designing a class and test program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Designing a class and test program" Watch "Designing a class and test program" New topic
Author

Designing a class and test program

Norman Neaderhiser
Greenhorn

Joined: Mar 10, 2004
Posts: 6
Hello guys and I hope that you are doing well.
I have written a program that creates a class and then I have created a test program. I would be gratefull if you could look at it and critique. Any suggestions as how to improve it would be welcome. I still have to finish commenting so that part is still rough. Thanks for your help NN

Now for the test program!

I know that this long. Is there a way to compress it? What observations do you have?
Thank you for your time and help
NN
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ April 04, 2004: Message edited by: Dirk Schreckmann ]
Carlos Failde
Ranch Hand

Joined: Oct 20, 2000
Posts: 84
Howdy pardner. Let's see...
Use ubb code tags around your code in future as it makes it easier to read.
Method names should be actions, so setSecondNumber() is better than secondNumber()
The body of getAverage() could be written as
return (firstTest+secondTest)/2;
There are many typographical errors and some cut and paste errors - the compiler will tell you where.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
A class and a test class are a great pairing. What a great habit to get into from the start! I'd guess this is for school work - if so your instructor is giving you some good ideas.
Here's a neat way to write tests so you don't have to examine the results closely by eye every time you run:

Now your tests just print a "." if they work, but give you a neat report if they fail.
One note, see how I had to turn the double result into a string with ""+method(). That's a little kludgey and a bit hard to predict. You might prefer another assertEquals method that takes two doubles as arguments.
This style comes from a test package called JUnit. It's maybe a bit advanced right now, but if you get into writing classes and tests (or tests BEFORE the classes!) you'll love it when you get to it.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
GeeCON Prague 2014
 
subject: Designing a class and test program