hi all,
im new here, its looks like a great forum i gald i found it.
here is my problem
i wrote a class that represnts a new langug
i got stuck here
i need to wirte a method that to this thig
CheckContinuity (int num, char c) public boolean method that accepts two parameters - a signal c integer num and returns a boolean value. The system checks whether there is a sequence of received signal c, as many times as num. If indeed there is a sequence number of letters that will return true, otherwise return no.
For example: reading method: CheckContinuity (2, A) operated on the object type MyLang his word feature is BAcAABAcAb checking that a sequence of 2 letters A and returns trueCheckContinuity (int num, char c) public boolean method that accepts two parameters - a signal c integer num and returns a boolean value. The system checks whether there is a sequence of received signal c, as many times as num. If indeed there is a sequence number of letters that will return true, otherwise return no.
For example: reading method: CheckContinuity (2, A) operated on the object type MyLang his word feature is BAcAABAcAb checking that a sequence of 2 letters A and returns true
please can some one help me
a little problem with a class
Page 1 of 112 Replies - 518 Views - Last Post: 07 January 2010 - 04:03 AM
Replies To: a little problem with a class
#2
Re: a little problem with a class
Posted 05 January 2010 - 02:42 PM
Hi, welcome to DIC! We'd be glad to help you, but you need to follow some of our guidelines as well. We do not just give out code here, you must provide some sort of effort first.
[rules][/rules]
[rules][/rules]
#3
Re: a little problem with a class
Posted 05 January 2010 - 02:46 PM
of course i dont want the answer i want an explanation
public class MyLang
{
// instance variables - replace the example below with your own
private String _word;
private static final int MAX_LENGTH=15;
/**
* Constructor for objects of class MyLang
*/
public MyLang (String w)
{
if (isValid(w)==true)
_word=w;
else
_word = "";
}
public boolean isValid(String s)
{
int len =s.length();
if (s.length() > MAX_LENGTH)
return false;
if (s.charAt(0)!='A'&&(s.charAt(0)!='B'))
return false;
if ((s.charAt(s.length()-1))=='c')
for ( int i=0; i<len; i++)
{
if (s.charAt(i)!='A' &&s.charAt(i)!='B' &&s.charAt(i)!='c')
return false;
}
for ( int i=0; i<len; i++)
{
if(s.charAt(i)=='c')
if((s.charAt(i-1)!='A') || (s.charAt(i+1)!='A'))
return false;
}
return true;
}
public char lastLetter()
{
if (_word=="")
return '\0';
else
return (_word.charAt(_word.length()-1));
}
public char letterInPlace(int i)
{
int abs=Math.abs(i);
if (_word.length()>abs)
return _word.charAt(abs);
else
return '\0';
}
public String toString()
{
return _word;
}
public boolean countA()
{
int counter =0;
for(int i=0; i<_word.length();i++)
{
if(_word.charAt(i)=='A')
counter++;
}
if ((counter%2)==0)
return true;
else
return false;
}
public int countUpper()
{
int counter =0;
for(int i=0; i<_word.length();i++)
{
if(_word.charAt(i)=='A' || (_word.charAt(i)=='B') )
counter++;
}
if (_word=="")
return '\0';
else
return counter;
}
public boolean addToWord(String other)
{
String add = _word+other;
return isValid(add);
}
public String eraseLetter(int i)
{
int abs1 = Math.abs(i);
if (abs1>_word.length())
return "";
String o1=_word.substring(0,abs1);
String o2=_word.substring(abs1+1);_word.length();
return (o1+o2);
}
public int getLastIndex(char c)
{
int last = -1;
for(int i=0; i<_word.length(); i++)
{
if (_word.charAt(i)== c)
last= i;
}
return last;
}
public boolean checkContinuity(int num,char c)
{
}
#4
Re: a little problem with a class
Posted 06 January 2010 - 10:02 AM
help anyone?
plz
plz
#5
Re: a little problem with a class
Posted 06 January 2010 - 10:20 AM
1984oran, on 6 Jan, 2010 - 04:02 PM, said:
help anyone?
plz
plz
You need to loop through the characters in _word, and check for an index i whether characters letterInPlace(i) up to letterInPlace(i+num) (num being the 1st parameter of checkContinuity) are equal to char c (the second param).
The good thing is that "your" letterInPlace is pretty idiot-proof, so you won't even need to check whether i+num is within the string...
This post has been edited by EdwinNameless: 06 January 2010 - 10:22 AM
#6
Re: a little problem with a class
Posted 06 January 2010 - 11:44 AM
thanks man,
you helped me alot
you helped me alot
#7
Re: a little problem with a class
Posted 06 January 2010 - 12:32 PM
hi all this is my code
i have problem writing this part of the program
int CheckWords (String other) - method receives another word and returns the number of int which is the number of letters in common between the two words. That is, the method returns the number of organs in the intersection between the two words. That is when identical letters in two words, then the method returns the number of letters there are both - that there is consideration of repeated letters. If the words completely identical returns the number 16 (using constant defined). If you do not cut all the words the method returns 0.
For instance, if a received word is BAcAB: BAcAA number will be returned 4. (The letters are highlighted cutting group
public class MyLang
{
// instance variables - replace the example below with your own
private String _word;
private static final int MAX_LENGTH=15;
/**
* Constructor for objects of class MyLang
*/
public MyLang (String w)
{
if (isValid(w)==true)
_word=w;
else
_word = "";
}
public boolean isValid(String s)
{
int len =s.length();
if (s.length() > MAX_LENGTH)
return false;
if (s.charAt(0)!='A'&&(s.charAt(0)!='B'))
return false;
if ((s.charAt(s.length()-1))=='c')
for ( int i=0; i<len; i++)
{
if (s.charAt(i)!='A' &&s.charAt(i)!='B' &&s.charAt(i)!='c')
return false;
}
for ( int i=0; i<len; i++)
{
if(s.charAt(i)=='c')
if((s.charAt(i-1)!='A') || (s.charAt(i+1)!='A'))
return false;
}
return true;
}
public char lastLetter()
{
if (_word=="")
return '\0';
else
return (_word.charAt(_word.length()-1));
}
public char letterInPlace(int i)
{
int abs=Math.abs(i);
if (_word.length()>abs)
return _word.charAt(abs);
else
return '\0';
}
public String toString()
{
return _word;
}
public boolean countA()
{
int counter =0;
for(int i=0; i<_word.length();i++)
{
if(_word.charAt(i)=='A')
counter++;
}
if ((counter%2)==0)
return true;
else
return false;
}
public int countUpper()
{
int counter =0;
for(int i=0; i<_word.length();i++)
{
if(_word.charAt(i)=='A' || (_word.charAt(i)=='B') )
counter++;
}
if (_word=="")
return '\0';
else
return counter;
}
public boolean addToWord(String other)
{
String add = _word+other;
return isValid(add);
}
public String eraseLetter(int i)
{
int abs1 = Math.abs(i);
if (abs1>_word.length())
return "";
String o1=_word.substring(0,abs1);
String o2=_word.substring(abs1+1);_word.length();
return (o1+o2);
}
public int getLastIndex(char c)
{
int last = -1;
for(int i=0; i<_word.length(); i++)
{
if (_word.charAt(i)== c)
last= i;
}
return last;
}
public boolean checkContinuity(int num,char c)
{
for(int i =0; letterInPlace(i)==c;letterInPlace(i+num))
return true;
return false;
}
i have problem writing this part of the program
int CheckWords (String other) - method receives another word and returns the number of int which is the number of letters in common between the two words. That is, the method returns the number of organs in the intersection between the two words. That is when identical letters in two words, then the method returns the number of letters there are both - that there is consideration of repeated letters. If the words completely identical returns the number 16 (using constant defined). If you do not cut all the words the method returns 0.
For instance, if a received word is BAcAB: BAcAA number will be returned 4. (The letters are highlighted cutting group
#8
Re: a little problem with a class
Posted 06 January 2010 - 12:41 PM
this is pretty simple, first compare them using the predefined equal() method..if they are equal then return 16 else loop through the string and compare each 2 corresponding characters..if they are equal then increment the count
#9
Re: a little problem with a class
Posted 06 January 2010 - 12:43 PM
how to compare with what?
#10
Re: a little problem with a class
Posted 06 January 2010 - 12:47 PM
the strings
if(str1.equals(str1)) return 16; //rest of the code here
#11
Re: a little problem with a class
Posted 06 January 2010 - 12:50 PM
Threads merged, please do not create duplicate threads on the same topic.
#12
Re: a little problem with a class
Posted 06 January 2010 - 12:53 PM
this part i know.
my problem is with the second part
my problem is with the second part
#13
Re: a little problem with a class
Posted 07 January 2010 - 04:03 AM
help please anyone?
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|