Results 1 to 13 of 13
Thread: Please help. blue j test method
- 06-02-2011, 02:37 AM #1
Member
- Join Date
- Jun 2011
- Posts
- 5
- Rep Power
- 0
Please help. blue j test method
hi there. i am new to this forum and was wondering if anyone could help me
i have a test that i need to pass, but i am have no luck..
the test code is
the method i need do write it for is :Java Code:public void testCuttingGrassReducesGrassAndProducesHay() { Hay hay = field.cutGrass(100); assertNotNull(hay); assertEquals(100, hay.getUnits()); assertEquals(0, field.getGrass()); }
any help or if needed more info please ask..Java Code:public Hay cutGrass(int grassToCut) { if( grassToCut <= 0){ throw new IllegalArgumentException("Cannot cut less than one unit of grass"); // if grass cut if less then one, exception thrown } if( grassToCut > 100){ throw new IllegalArgumentException("Cannot cut more grass than field contains"); // if grass cut contains more then in field exception is thrown. } if (month >= 12){ // if month is more then or equal to 12 the grass cut goes is set back to 0. grass =0; } report("cut " + grassToCut + " units of grass"); return hay; }
thanksLast edited by chang-; 06-02-2011 at 02:40 AM.
- 06-02-2011, 02:42 AM #2
The cutGrass method must create an instance of the Hay class and return it. Since we have no idea what the Hay class looks like we cannot offer more advice.
By the way the IDE (bluej) you use is irrelevant.
- 06-02-2011, 02:45 AM #3
Member
- Join Date
- Jun 2011
- Posts
- 5
- Rep Power
- 0
the hay class just has one constructor in it
sorry i dnt understand what you mean by blue j's is irrelvant?Java Code:public Hay(int units) { super(units, 1); }
- 06-02-2011, 02:50 AM #4
You mentioned that you are using bluej as if it has some impact on your code. It doesn't. You would have the same problem if you wrote your code in Eclipse, Netbeans, JBuilder, ItelliJ, notpad etc. So mentioning what IDE you use is of no importance to us.
- 06-02-2011, 02:51 AM #5
OK so now you have added code to the cutGrass method. What problem are you having? For starters I cannot see where you create an instance of the Hay class.
- 06-02-2011, 02:55 AM #6
Member
- Join Date
- Jun 2011
- Posts
- 5
- Rep Power
- 0
im having troube on writing the instance that calls from the hay class. so far i have
i know its number of units should be in its parameter, but i dont know how to write it.Java Code:hay = new Hay();
oh ok sorry i didnt knw
- 06-02-2011, 02:57 AM #7
Member
- Join Date
- Jun 2011
- Posts
- 5
- Rep Power
- 0
oh sorry i figured it out it was .
but when i run the test. the test says it expected 0 but got 100Java Code:hay = new Hay(grassToCut);
- 06-02-2011, 03:00 AM #8
In your first post you passed a parameter to a method. The code passes 100 to the method cutGrass().Java Code:Hay hay = field.cutGrass(100);
A constructor is a special kind of method and you pass parameters to it the same way.
Look at the constructor and see what type of data is required. Then make sure the number of units is that data type.
- 06-02-2011, 03:01 AM #9
Don't think about this in Java terms, think about it in real terms. After you cut the grass of a lawn/field/etc how much grass would there be?
- 06-02-2011, 03:13 AM #10
Member
- Join Date
- Jun 2011
- Posts
- 5
- Rep Power
- 0
more then 1 unit of grass?
- 06-02-2011, 03:17 AM #11
What is the meaning of the parameter to the Hay constructor?
How do you know what value to give to it? Is there any documentation for the class that tells you?
No one here can know that number. It has to come from your professor or some part of the program.
- 06-02-2011, 03:17 AM #12
Let me try another tack. If you lawn had 1000 units of grass and you cut 250 units and made it into hay, how much grass would your lawn still have?
- 06-02-2011, 04:29 AM #13
I don't respond to private messages. If you have a question to ask then do it on the forum.
No. I believe people learn better if they write it themselves.hi would it be possible if i could send you my code, to give u a beter understanding.
It is simple math.i would sitll have 750 units of grass left..
but i dont know how to write this as code
What would you replace the dots with so x had the final value of 750?Java Code:int x = 1000; int y = 250; x = .......;
Similar Threads
-
How to test a void method in Junit?
By jRookie in forum New To JavaReplies: 7Last Post: 09-01-2010, 07:47 AM -
Test Advisory Panel-Telecommute- Test your Java skills + share insights on Java tests
By michelle in forum Jobs OfferedReplies: 0Last Post: 04-05-2008, 12:38 AM -
Open Blue Lab 1.3.2
By levent in forum Java SoftwareReplies: 0Last Post: 08-01-2007, 04:22 PM -
Open Blue Lab 1.3.0
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-19-2007, 03:37 PM -
Open Blue Lab 1.2.10
By levent in forum Java SoftwareReplies: 0Last Post: 05-19-2007, 08:08 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks