reset password
Author Message
Anonymous
Posts: 166
Posted 21:57 Jan 29, 2014 |

are we suppose to create junit testers for the home work or can we just make easier testers that just print the values. for example for E5.1 it would be much easier to just use scanner to print the sign of the number, I keep getting errors using junit but i know that the sign of 20 is positive, there is no need for a tester for that. or how can i make a junit test for it. only p5.2 requires a junit tester.

rabbott
Posts: 1649
Posted 23:28 Jan 29, 2014 |

Please see the extended homework descriptions. Although it may seem like a lot of code for such a simple problem, this is standard practice. It's good to get used to it.

Last edited by rabbott at 23:29 Jan 29, 2014.
ladodgersfan
Posts: 13
Posted 22:18 Jan 30, 2014 |

what exactly is the auxiliary method going to do. the main method already sets up what the input will be. positive, negative or zero.

i did it differently since i started on Wednesday before the new instructions were updated. this is what i have im just having problems creating a junit test.

public class E5_1
{
    private int integer;

    public E5_1(int integer)
    {
       this.integer = integer;
    }
    
    public int sign()
    {
        
        if(integer == 0 )
        {
            System.out.println("the number is zero");
        }
        if(integer < 0)
        {
            System.out.println("the number is negative");
        }
        else if (integer > 0)
        {
            System.out.println("the number is positive");
        }
        return integer;
    }
    }

rabbott
Posts: 1649
Posted 22:48 Jan 30, 2014 |
Your sign method mixes two things. It both determines positive or negative and it does I/O. That's poor style. One method should determine positive or negative. Another should call it and tell the user the answer. JUnit test methods should be used to test methods that do a computation and return a result.