السلام عليكم
لدي سؤال على برنامج الـ "بلو جي" لم اعرف طريقة الحل ولكن حاولت و احتاج اجابته اليوم
فأتمنى منكم المساعده
السؤال هو:
1) Create a Class with the name"MyCollege".
2) Declare aString variable called "myCol" which has the sollowing text in it:-
The College of Information Technology CIT was founded in 2001. The mission of the CIT is to offer solid student centered programs. The CIT was designed so as to bring down the traditional walls that separate departments within a college. All CIT courses are developed and taught using the Blackboard course management system and the entire CIT campus is equipped with wireless internet access
You are required to do the following:
3) Create a method called "counWordShortThan" inside the MyCollege class which is suppose to count the number of words in"var" string variable whose lengths are less than an input value "wordLen"
Public int countWordsShorterThan(String var, int wordLen)
4) in the main () method, call the countWordsShorterThan(myCol,5) to count the number of words in "myCol" string variable whose lengths are less than 5 and print the number on screen.
والحل اللي حاولته هو :
public class MyCollege
{
// instance variables - replace the example below with your own
private String myCol;
private String var;
private String wordLen;
/**
* Constructor for objects of class MyCollege
*/
public MyCollege()
{
// initialise instance variables
myCol = "The College of Information Technology CIT was founded in 2001. The mission of the CIT is to offer solid student centered programs. The CIT was designed so as to bring down the traditional walls that separate departments within a college. All CIT courses are developed and taught using the Blackboard course management system and the entire CIT campus is equipped with wireless internet access.";
}
public String mycol( String wordLen)
{
return wordLen.length();
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public boolean countWordsShorterThan(String var, int wordLen)
{
if (var.length < wordLen)
return myCol.length();
else
return false;
}
}
