The Artima Developer Community
Sponsored Link

Java Answers Forum
help with a constructor if it doesn't accept string arguments

2 replies on 1 page. Most recent reply: Mar 19, 2006 11:59 PM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Michelle Loh

Posts: 10
Nickname: modernage
Registered: Feb, 2006

help with a constructor if it doesn't accept string arguments Posted: Mar 19, 2006 6:03 PM
Reply to this message Reply
Advertisement
what if i wanted to return a new Set object (towards the bottom of the code) as a string, but the constructor
doesn't accept String arguments, how do i write the methods to correct that?

public class Set
{
// define fields here


public Set(int maxinteger)
{
// complete this method
}

public boolean add(int integer)
{
return false; // replace this line with your code
}

public boolean remove(int integer)
{
return false; // replace this line with your code
}

public boolean contains(int integer)
{
return false; // replace this line with your code
}

public int size()
{
return 0; // replace this line with your code
}

public String toString()
{
return null; // replace this line with your code
}

public void addAll(Set other)
{
// complete this method
}

public Set subset(int min, int max)[b]<------[/b]
{
return null; // replace this line with your code
}

public Set intersection(Set other)[b]<------[/b]
{
return null; // replace this line with your code
}

public Set difference(Set other)[b]<-----[/b]
{
return null; // replace this line with your code
}
}


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: help with a constructor if it doesn't accept string arguments Posted: Mar 19, 2006 11:56 PM
Reply to this message Reply
Write an additional constructor which accepts a String argument.
You allready have one accepting int.
Copy it and change int to String.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: help with a constructor if it doesn't accept string arguments Posted: Mar 19, 2006 11:59 PM
Reply to this message Reply
If you don't want to create an additional constructor, convert your String argument tointeger using Integer.parseInt(argument)

Flat View: This topic has 2 replies on 1 page
Topic: Java If statement (blacklist) Previous Topic   Next Topic Topic: NetBeans 4.1..why this problem?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use