Call the constructor with 2 valid arguments?

Call the constructor with 2 valid arguments?

Page 1 of 1

2 Replies - 1434 Views - Last Post: 12 April 2010 - 07:49 AM Rate Topic: -----

#1 XMEGA  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 17-November 08

Call the constructor with 2 valid arguments?

Posted 12 April 2010 - 06:55 AM

how would you for the positive test method, call the constructor with 2 valid arguments? fullName and emailAddress?

member test servlet
public class MemberTest extends TestCase
{
    
    public MemberTest(String testName)
    {
        super(testName);
    }

public void testValidNegative()
{
System.out.println("isValid Negative Test Case");
Member instance = new Member();
boolean expResult = false;
boolean result = instance.isValid();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
}

public void testValidPositive()
{
System.out.println("isValid Positive Test Case");
Member instance = new Member();
boolean expResult = true;
boolean result = instance.isValid();
assertEquals(expResult, result );
// TODO review the generated test code and remove the default call to fail.
}
}




this is whats in the member servlet
package club.business;

import java.io.Serializable;

public class Member implements Serializable
{
    private String fullName = "";
    private String emailAddress = "";
    private String phoneNumber = "";
    private String programName = "";
    private int yearLevel = 0;
    private boolean valid = false;

    public Member()
    {
        fullName = "";
        emailAddress = "";
        phoneNumber = "";
        programName = "";
        yearLevel = 0;
    }

    public Member(String full, String email)
    {
        fullName = full;
        emailAddress = email;
    }

    public String getFullName()
    {
        return fullName;
    }

    public void setFullName(String fullName)
    {
        this.fullName = fullName;
    }

    public String getEmailAddress()
    {
        return emailAddress;
    }

    public void setEmailAddress(String emailAddress)
    {
        this.emailAddress = emailAddress;
    }

    public String getPhoneNumber()
    {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber)
    {
        this.phoneNumber = phoneNumber;
    }

    public String getProgramName()
    {
        return programName;
    }

    public void setProgramName(String programName)
    {
        this.programName = programName;
    }

    public int getYearLevel()
    {
        return yearLevel;
    }

    public void setYearLevel(int yearLevel)
    {
        this.yearLevel = yearLevel;
    }

    public boolean isValid()
    {
        if ((getFullName().length() > 0) && (getEmailAddress().length() > 0))
        {
            valid = true;
        }
        else
        {
            valid = false;
        }
        return valid;
    }
}


This post has been edited by XMEGA: 12 April 2010 - 07:36 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Call the constructor with 2 valid arguments?

#2 pdkharkar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 345
  • Joined: 19-January 09

Re: Call the constructor with 2 valid arguments?

Posted 12 April 2010 - 07:25 AM

your code is not so clear to me
I could have helped in a better way if you had provided full code
look
for calling the constructor with two valid arguments, you have to define a constructor for that first
this is called as constructor overloading
for example

Class instance = new Class()// this is no arg constructor
{
// initialization goes here
}

for two arg constructor you have to write as
Class instance = new Class(String fullName, String address){
//initialization goes here

} // takes two arguments

This post has been edited by pdkharkar: 12 April 2010 - 07:26 AM

Was This Post Helpful? 1
  • +
  • -

#3 XMEGA  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 17-November 08

Re: Call the constructor with 2 valid arguments?

Posted 12 April 2010 - 07:49 AM

View Postpdkharkar, on 12 April 2010 - 06:25 AM, said:

your code is not so clear to me
I could have helped in a better way if you had provided full code
look
for calling the constructor with two valid arguments, you have to define a constructor for that first
this is called as constructor overloading
for example

Class instance = new Class()// this is no arg constructor
{
// initialization goes here
}

for two arg constructor you have to write as
Class instance = new Class(String fullName, String address){
//initialization goes here

} // takes two arguments

I was able to solve it thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1