«« ( Date ) »» // «« ( Thread ) »» // si3ts - 2011

SI3TS DZ2 - Djordje Vukovic 08/0529

by Đorđe Vuković 08/0529
sreda, 05. januar 2011 - 00:05.



public class StringManipulation {

public StringManipulation(String input)
{
str = input;
}

private String str;
private int numberOfChars=0;
private int numberOfDigits=0;

public int GetNumberOfCharacters() { return numberOfChars; }
public int GetNumberOfDigits() {return numberOfDigits;}
public void SetString(String s)
{
str = s;
numberOfDigits=0;
numberOfChars=0;
}

public int ASCIIsum()
{
int zbir=0;

for(int i=0; i < str.length(); i++)
{
zbir+=(int)str.charAt(i);
}

return zbir;
}

public void Analyse()
{
int index = 0;
while(index<str.length())
{
if(Character.isDigit(str.charAt(index)))
{
numberOfDigits++;
}
if(Character.isLetter(str.charAt(index)))
{
numberOfChars++;
}
}
}

public boolean isDigit(int index)
{
for(int i=0; i<str.length(); i++)
{
if(i==index)
{
char c = str.charAt(i);
if(Character.isDigit(c))
{
return true;
}
else
{
return false;
}
}
}
return false;
}

public boolean isLetter(int index)
{
for(int i=0; i<str.length(); i++)
{
if(i==index)
{
char c = str.charAt(i);
if(Character.isLetter(c))
{
return true;
}
else
{
return false;
}
}
}
return false;
}
}