-
Return a Vector
Hi,
I am having a problem with some code for part of a project I have included
it below. The problem I am having is to do with (List all subjects) method,
I need to return a vector of subjects and I am having a problem with this
method any help would be appreciated.
Thanks
***********************************************************************
import java.io.*;
import java.util.*;
public class Student
{
private Vector mSubjects = new Vector();
private String mStudentnumber;
private String mFirstname;
private String mLastname;
private boolean mConcession;
public Student(String Studentnumber,String Firstname
, String Lastname, boolean Concession)
{
mStudentnumber = Studentnumber;
mFirstname = Firstname;
mLastname = Lastname;
mConcession = false;
}
public String GetName()
{
return mFirstname + ' ' + mLastname;
}
public String GetNumber()
{
return mStudentnumber;
}
public boolean Status()
{
return mConcession;
}
public boolean AddSubject(Subject InSubject)
{
if (mSubjects.contains(InSubject))
{
return false;
}
else
{
mSubjects.addElement(InSubject);
return true;
}
}
public boolean DeleteSubject(Subject InSubject)
{
if (mSubjects.contains(InSubject))
{
mSubjects.removeElement(InSubject);
return true;
}
else
{
return false;
}
}
public Subject FindSubject(String GetNumber)
{
int Num = mSubjects.size();
boolean found = false;
Subject InSubject = null;
for(int i = 0; i < Num && !found; i++)
{
InSubject = (Subject)mSubjects.elementAt(i);
if (InSubject.GetNumber().equals(GetNumber))
{
found = true;
}
}
if(!found)
InSubject = null;
return InSubject;
}
public int NumberSubjects()
{
return mSubjects.size();
}
public Subject ListSubjects()
{
}
}
***********************************************************************
-
Re: Return a Vector
If I understand what you are asking ...
public Subject ListSubjects()
{
return mSubjects;
}
"Whitewolf" <whitewolf@digitalrice.com> wrote:
>
>Hi,
>
>I am having a problem with some code for part of a project I have included
>it below. The problem I am having is to do with (List all subjects) method,
>I need to return a vector of subjects and I am having a problem with this
>method any help would be appreciated.
>
>Thanks
>
>
>***********************************************************************
>import java.io.*;
>import java.util.*;
>
>public class Student
>{
> private Vector mSubjects = new Vector();
> private String mStudentnumber;
> private String mFirstname;
> private String mLastname;
> private boolean mConcession;
>
> public Student(String Studentnumber,String Firstname
> , String Lastname, boolean Concession)
> {
> mStudentnumber = Studentnumber;
> mFirstname = Firstname;
> mLastname = Lastname;
> mConcession = false;
> }
>
> public String GetName()
> {
> return mFirstname + ' ' + mLastname;
> }
>
> public String GetNumber()
> {
> return mStudentnumber;
> }
>
> public boolean Status()
> {
> return mConcession;
> }
>
> public boolean AddSubject(Subject InSubject)
> {
> if (mSubjects.contains(InSubject))
> {
> return false;
> }
> else
> {
> mSubjects.addElement(InSubject);
> return true;
> }
> }
>
> public boolean DeleteSubject(Subject InSubject)
> {
> if (mSubjects.contains(InSubject))
> {
> mSubjects.removeElement(InSubject);
> return true;
> }
> else
> {
> return false;
> }
> }
>
> public Subject FindSubject(String GetNumber)
> {
> int Num = mSubjects.size();
> boolean found = false;
> Subject InSubject = null;
> for(int i = 0; i < Num && !found; i++)
> {
> InSubject = (Subject)mSubjects.elementAt(i);
> if (InSubject.GetNumber().equals(GetNumber))
> {
> found = true;
> }
> }
> if(!found)
> InSubject = null;
> return InSubject;
> }
>
>
> public int NumberSubjects()
> {
> return mSubjects.size();
> }
>
> public Subject ListSubjects()
> {
>
> }
>}
>
>***********************************************************************
-
Re: Return a Vector
Yes it is along those lines, but when I compile I get this error
(C:\My Documents\Java\***\Student.java:88: incompatible types
found : java.util.Vector
required: java.lang.String
return mSubjects;
^
1 error
Process completed.)
Do I need to do a cast if so what would be the code.
Thanks
"MarkN" <java.@127.0.0.1> wrote:
>
>If I understand what you are asking ...
>
>public Subject ListSubjects()
>{
> return mSubjects;
>}
>
>
>"Whitewolf" <whitewolf@digitalrice.com> wrote:
>>
>>Hi,
>>
>>I am having a problem with some code for part of a project I have included
>>it below. The problem I am having is to do with (List all subjects) method,
>>I need to return a vector of subjects and I am having a problem with this
>>method any help would be appreciated.
>>
>>Thanks
>>
>>
>>***********************************************************************
>
>>import java.io.*;
>>import java.util.*;
>>
>>public class Student
>>{
>> private Vector mSubjects = new Vector();
>> private String mStudentnumber;
>> private String mFirstname;
>> private String mLastname;
>> private boolean mConcession;
>>
>> public Student(String Studentnumber,String Firstname
>> , String Lastname, boolean Concession)
>> {
>> mStudentnumber = Studentnumber;
>> mFirstname = Firstname;
>> mLastname = Lastname;
>> mConcession = false;
>> }
>>
>> public String GetName()
>> {
>> return mFirstname + ' ' + mLastname;
>> }
>>
>> public String GetNumber()
>> {
>> return mStudentnumber;
>> }
>>
>> public boolean Status()
>> {
>> return mConcession;
>> }
>>
>> public boolean AddSubject(Subject InSubject)
>> {
>> if (mSubjects.contains(InSubject))
>> {
>> return false;
>> }
>> else
>> {
>> mSubjects.addElement(InSubject);
>> return true;
>> }
>> }
>>
>> public boolean DeleteSubject(Subject InSubject)
>> {
>> if (mSubjects.contains(InSubject))
>> {
>> mSubjects.removeElement(InSubject);
>> return true;
>> }
>> else
>> {
>> return false;
>> }
>> }
>>
>> public Subject FindSubject(String GetNumber)
>> {
>> int Num = mSubjects.size();
>> boolean found = false;
>> Subject InSubject = null;
>> for(int i = 0; i < Num && !found; i++)
>> {
>> InSubject = (Subject)mSubjects.elementAt(i);
>> if (InSubject.GetNumber().equals(GetNumber))
>> {
>> found = true;
>> }
>> }
>> if(!found)
>> InSubject = null;
>> return InSubject;
>> }
>>
>>
>> public int NumberSubjects()
>> {
>> return mSubjects.size();
>> }
>>
>> public Subject ListSubjects()
>> {
>>
>> }
>>}
>>
>>***********************************************************************
>
-
Re: Return a Vector
If you want to return a Vector, just say so:
public Vector ListSubjects()
{
return mSubjects;
}
PC2
"Whitewolf" <whitewolf@digitalrice.com> wrote in message
news:3cda6a39$1@10.1.10.29...
>
> Yes it is along those lines, but when I compile I get this error
> (C:\My Documents\Java\***\Student.java:88: incompatible types
> found : java.util.Vector
> required: java.lang.String
> return mSubjects;
> ^
> 1 error
>
> Process completed.)
>
> Do I need to do a cast if so what would be the code.
>
> Thanks
>
>
> "MarkN" <java.@127.0.0.1> wrote:
> >
> >If I understand what you are asking ...
> >
> >public Subject ListSubjects()
> >{
> > return mSubjects;
> >}
> >
> >
> >"Whitewolf" <whitewolf@digitalrice.com> wrote:
> >>
> >>Hi,
> >>
> >>I am having a problem with some code for part of a project I have
included
> >>it below. The problem I am having is to do with (List all subjects)
method,
> >>I need to return a vector of subjects and I am having a problem with
this
> >>method any help would be appreciated.
> >>
> >>Thanks
> >>
> >>
> >>***********************************************************************
> >
> >>import java.io.*;
> >>import java.util.*;
> >>
> >>public class Student
> >>{
> >> private Vector mSubjects = new Vector();
> >> private String mStudentnumber;
> >> private String mFirstname;
> >> private String mLastname;
> >> private boolean mConcession;
> >>
> >> public Student(String Studentnumber,String Firstname
> >> , String Lastname, boolean Concession)
> >> {
> >> mStudentnumber = Studentnumber;
> >> mFirstname = Firstname;
> >> mLastname = Lastname;
> >> mConcession = false;
> >> }
> >>
> >> public String GetName()
> >> {
> >> return mFirstname + ' ' + mLastname;
> >> }
> >>
> >> public String GetNumber()
> >> {
> >> return mStudentnumber;
> >> }
> >>
> >> public boolean Status()
> >> {
> >> return mConcession;
> >> }
> >>
> >> public boolean AddSubject(Subject InSubject)
> >> {
> >> if (mSubjects.contains(InSubject))
> >> {
> >> return false;
> >> }
> >> else
> >> {
> >> mSubjects.addElement(InSubject);
> >> return true;
> >> }
> >> }
> >>
> >> public boolean DeleteSubject(Subject InSubject)
> >> {
> >> if (mSubjects.contains(InSubject))
> >> {
> >> mSubjects.removeElement(InSubject);
> >> return true;
> >> }
> >> else
> >> {
> >> return false;
> >> }
> >> }
> >>
> >> public Subject FindSubject(String GetNumber)
> >> {
> >> int Num = mSubjects.size();
> >> boolean found = false;
> >> Subject InSubject = null;
> >> for(int i = 0; i < Num && !found; i++)
> >> {
> >> InSubject = (Subject)mSubjects.elementAt(i);
> >> if (InSubject.GetNumber().equals(GetNumber))
> >> {
> >> found = true;
> >> }
> >> }
> >> if(!found)
> >> InSubject = null;
> >> return InSubject;
> >> }
> >>
> >>
> >> public int NumberSubjects()
> >> {
> >> return mSubjects.size();
> >> }
> >>
> >> public Subject ListSubjects()
> >> {
> >>
> >> }
> >>}
> >>
> >>***********************************************************************
> >
>
-
Re: Return a Vector
If you want to (List all subjects) ... try this or use Paul suggestons
public Subject ListSubjects()
{
return mSubjects.toString();
}
"Whitewolf" <whitewolf@digitalrice.com> 撰寫於郵件
news:3cda6a39$1@10.1.10.29...
>
> Yes it is along those lines, but when I compile I get this error
> (C:\My Documents\Java\***\Student.java:88: incompatible types
> found : java.util.Vector
> required: java.lang.String
> return mSubjects;
> ^
> 1 error
>
> Process completed.)
>
> Do I need to do a cast if so what would be the code.
>
> Thanks
>
>
> "MarkN" <java.@127.0.0.1> wrote:
> >
> >If I understand what you are asking ...
> >
> >public Subject ListSubjects()
> >{
> > return mSubjects;
> >}
> >
> >
> >"Whitewolf" <whitewolf@digitalrice.com> wrote:
> >>
> >>Hi,
> >>
> >>I am having a problem with some code for part of a project I have
included
> >>it below. The problem I am having is to do with (List all subjects)
method,
> >>I need to return a vector of subjects and I am having a problem with
this
> >>method any help would be appreciated.
> >>
> >>Thanks
> >>
> >>
> >>***********************************************************************
> >
> >>import java.io.*;
> >>import java.util.*;
> >>
> >>public class Student
> >>{
> >> private Vector mSubjects = new Vector();
> >> private String mStudentnumber;
> >> private String mFirstname;
> >> private String mLastname;
> >> private boolean mConcession;
> >>
> >> public Student(String Studentnumber,String Firstname
> >> , String Lastname, boolean Concession)
> >> {
> >> mStudentnumber = Studentnumber;
> >> mFirstname = Firstname;
> >> mLastname = Lastname;
> >> mConcession = false;
> >> }
> >>
> >> public String GetName()
> >> {
> >> return mFirstname + ' ' + mLastname;
> >> }
> >>
> >> public String GetNumber()
> >> {
> >> return mStudentnumber;
> >> }
> >>
> >> public boolean Status()
> >> {
> >> return mConcession;
> >> }
> >>
> >> public boolean AddSubject(Subject InSubject)
> >> {
> >> if (mSubjects.contains(InSubject))
> >> {
> >> return false;
> >> }
> >> else
> >> {
> >> mSubjects.addElement(InSubject);
> >> return true;
> >> }
> >> }
> >>
> >> public boolean DeleteSubject(Subject InSubject)
> >> {
> >> if (mSubjects.contains(InSubject))
> >> {
> >> mSubjects.removeElement(InSubject);
> >> return true;
> >> }
> >> else
> >> {
> >> return false;
> >> }
> >> }
> >>
> >> public Subject FindSubject(String GetNumber)
> >> {
> >> int Num = mSubjects.size();
> >> boolean found = false;
> >> Subject InSubject = null;
> >> for(int i = 0; i < Num && !found; i++)
> >> {
> >> InSubject = (Subject)mSubjects.elementAt(i);
> >> if (InSubject.GetNumber().equals(GetNumber))
> >> {
> >> found = true;
> >> }
> >> }
> >> if(!found)
> >> InSubject = null;
> >> return InSubject;
> >> }
> >>
> >>
> >> public int NumberSubjects()
> >> {
> >> return mSubjects.size();
> >> }
> >>
> >> public Subject ListSubjects()
> >> {
> >>
> >> }
> >>}
> >>
> >>***********************************************************************
> >
>
-
Re: Return a Vector
Thanks for the help its all sorted out now.
"Soft Solution System Limited" <support@3s.com.hk> wrote:
>If you want to (List all subjects) ... try this or use Paul suggestons
>
>public Subject ListSubjects()
>{
> return mSubjects.toString();
>}
>
>
>
>"Whitewolf" <whitewolf@digitalrice.com> 撰寫於郵件
>news:3cda6a39$1@10.1.10.29...
>>
>> Yes it is along those lines, but when I compile I get this error
>> (C:\My Documents\Java\***\Student.java:88: incompatible types
>> found : java.util.Vector
>> required: java.lang.String
>> return mSubjects;
>> ^
>> 1 error
>>
>> Process completed.)
>>
>> Do I need to do a cast if so what would be the code.
>>
>> Thanks
>>
>>
>> "MarkN" <java.@127.0.0.1> wrote:
>> >
>> >If I understand what you are asking ...
>> >
>> >public Subject ListSubjects()
>> >{
>> > return mSubjects;
>> >}
>> >
>> >
>> >"Whitewolf" <whitewolf@digitalrice.com> wrote:
>> >>
>> >>Hi,
>> >>
>> >>I am having a problem with some code for part of a project I have
>included
>> >>it below. The problem I am having is to do with (List all subjects)
>method,
>> >>I need to return a vector of subjects and I am having a problem with
>this
>> >>method any help would be appreciated.
>> >>
>> >>Thanks
>> >>
>> >>
>> >>***********************************************************************
>> >
>> >>import java.io.*;
>> >>import java.util.*;
>> >>
>> >>public class Student
>> >>{
>> >> private Vector mSubjects = new Vector();
>> >> private String mStudentnumber;
>> >> private String mFirstname;
>> >> private String mLastname;
>> >> private boolean mConcession;
>> >>
>> >> public Student(String Studentnumber,String Firstname
>> >> , String Lastname, boolean Concession)
>> >> {
>> >> mStudentnumber = Studentnumber;
>> >> mFirstname = Firstname;
>> >> mLastname = Lastname;
>> >> mConcession = false;
>> >> }
>> >>
>> >> public String GetName()
>> >> {
>> >> return mFirstname + ' ' + mLastname;
>> >> }
>> >>
>> >> public String GetNumber()
>> >> {
>> >> return mStudentnumber;
>> >> }
>> >>
>> >> public boolean Status()
>> >> {
>> >> return mConcession;
>> >> }
>> >>
>> >> public boolean AddSubject(Subject InSubject)
>> >> {
>> >> if (mSubjects.contains(InSubject))
>> >> {
>> >> return false;
>> >> }
>> >> else
>> >> {
>> >> mSubjects.addElement(InSubject);
>> >> return true;
>> >> }
>> >> }
>> >>
>> >> public boolean DeleteSubject(Subject InSubject)
>> >> {
>> >> if (mSubjects.contains(InSubject))
>> >> {
>> >> mSubjects.removeElement(InSubject);
>> >> return true;
>> >> }
>> >> else
>> >> {
>> >> return false;
>> >> }
>> >> }
>> >>
>> >> public Subject FindSubject(String GetNumber)
>> >> {
>> >> int Num = mSubjects.size();
>> >> boolean found = false;
>> >> Subject InSubject = null;
>> >> for(int i = 0; i < Num && !found; i++)
>> >> {
>> >> InSubject = (Subject)mSubjects.elementAt(i);
>> >> if (InSubject.GetNumber().equals(GetNumber))
>> >> {
>> >> found = true;
>> >> }
>> >> }
>> >> if(!found)
>> >> InSubject = null;
>> >> return InSubject;
>> >> }
>> >>
>> >>
>> >> public int NumberSubjects()
>> >> {
>> >> return mSubjects.size();
>> >> }
>> >>
>> >> public Subject ListSubjects()
>> >> {
>> >>
>> >> }
>> >>}
>> >>
>> >>***********************************************************************
>> >
>>
>
>
-
Re: Return a Vector
Would another solution be to create a new class called Subjects that is derived
from a suitable JDK collection class such as AbstractList?
You could then do the following
replace
private Vector mSubjects = new Vector();
with
private Subjects mSubjects = new Subjects();
You could then be in complete control of the collection interface you pass
around and return a real collection of your own type to clients. This would
be very type safe solution if you require this level of functionality.
Steve I
"Whitewolf" <whitewolf@digitalrice.com> wrote:
>
>Thanks for the help its all sorted out now.
>
>"Soft Solution System Limited" <support@3s.com.hk> wrote:
>>If you want to (List all subjects) ... try this or use Paul suggestons
>>
>>public Subject ListSubjects()
>>{
>> return mSubjects.toString();
>>}
>>
>>
>>
>>"Whitewolf" <whitewolf@digitalrice.com> 撰寫於郵件
>>news:3cda6a39$1@10.1.10.29...
>>>
>>> Yes it is along those lines, but when I compile I get this error
>>> (C:\My Documents\Java\***\Student.java:88: incompatible types
>>> found : java.util.Vector
>>> required: java.lang.String
>>> return mSubjects;
>>> ^
>>> 1 error
>>>
>>> Process completed.)
>>>
>>> Do I need to do a cast if so what would be the code.
>>>
>>> Thanks
>>>
>>>
>>> "MarkN" <java.@127.0.0.1> wrote:
>>> >
>>> >If I understand what you are asking ...
>>> >
>>> >public Subject ListSubjects()
>>> >{
>>> > return mSubjects;
>>> >}
>>> >
>>> >
>>> >"Whitewolf" <whitewolf@digitalrice.com> wrote:
>>> >>
>>> >>Hi,
>>> >>
>>> >>I am having a problem with some code for part of a project I have
>>included
>>> >>it below. The problem I am having is to do with (List all subjects)
>>method,
>>> >>I need to return a vector of subjects and I am having a problem with
>>this
>>> >>method any help would be appreciated.
>>> >>
>>> >>Thanks
>>> >>
>>> >>
>>> >>***********************************************************************
>>> >
>>> >>import java.io.*;
>>> >>import java.util.*;
>>> >>
>>> >>public class Student
>>> >>{
>>> >> private Vector mSubjects = new Vector();
>>> >> private String mStudentnumber;
>>> >> private String mFirstname;
>>> >> private String mLastname;
>>> >> private boolean mConcession;
>>> >>
>>> >> public Student(String Studentnumber,String Firstname
>>> >> , String Lastname, boolean Concession)
>>> >> {
>>> >> mStudentnumber = Studentnumber;
>>> >> mFirstname = Firstname;
>>> >> mLastname = Lastname;
>>> >> mConcession = false;
>>> >> }
>>> >>
>>> >> public String GetName()
>>> >> {
>>> >> return mFirstname + ' ' + mLastname;
>>> >> }
>>> >>
>>> >> public String GetNumber()
>>> >> {
>>> >> return mStudentnumber;
>>> >> }
>>> >>
>>> >> public boolean Status()
>>> >> {
>>> >> return mConcession;
>>> >> }
>>> >>
>>> >> public boolean AddSubject(Subject InSubject)
>>> >> {
>>> >> if (mSubjects.contains(InSubject))
>>> >> {
>>> >> return false;
>>> >> }
>>> >> else
>>> >> {
>>> >> mSubjects.addElement(InSubject);
>>> >> return true;
>>> >> }
>>> >> }
>>> >>
>>> >> public boolean DeleteSubject(Subject InSubject)
>>> >> {
>>> >> if (mSubjects.contains(InSubject))
>>> >> {
>>> >> mSubjects.removeElement(InSubject);
>>> >> return true;
>>> >> }
>>> >> else
>>> >> {
>>> >> return false;
>>> >> }
>>> >> }
>>> >>
>>> >> public Subject FindSubject(String GetNumber)
>>> >> {
>>> >> int Num = mSubjects.size();
>>> >> boolean found = false;
>>> >> Subject InSubject = null;
>>> >> for(int i = 0; i < Num && !found; i++)
>>> >> {
>>> >> InSubject = (Subject)mSubjects.elementAt(i);
>>> >> if (InSubject.GetNumber().equals(GetNumber))
>>> >> {
>>> >> found = true;
>>> >> }
>>> >> }
>>> >> if(!found)
>>> >> InSubject = null;
>>> >> return InSubject;
>>> >> }
>>> >>
>>> >>
>>> >> public int NumberSubjects()
>>> >> {
>>> >> return mSubjects.size();
>>> >> }
>>> >>
>>> >> public Subject ListSubjects()
>>> >> {
>>> >>
>>> >> }
>>> >>}
>>> >>
>>> >>***********************************************************************
>>> >
>>>
>>
>>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|