Because you actually took the time to format your code,
I will assist you with your homework (clearly this
is a homework problem - am I wrong?)
> Im sorry, i don't know how to get to u. I saw ur reply to
> ogeela and sabrina's question.
> Its the same as mine but they wrote the codes wrongly.
> This is the real thing. Pls c if u can help.
> Thank u.
>
> > Task 1
> ------
> Class, Inheritance, String Processing, Sorting, Searching
>
> Consider the code:
> ------------------
>
[pre]
public class Meth1
{
/*
* @description: This method ensures that every
* word in array q exists in p
* @returns: true if everything in q has
* an equivalent word in p
*/
public static boolean words(String[]p,String[]q)
{
// initially set to true;
boolean flag=true;
// self explanatory for loop
for(int i=0;(i<q.length && flag);i++)
flag=(look(p,q[i]));
// was I found (if true at the end
// every word in q is available in p
return flag;
}//words
/*
* @description: does w exist in array of words p,
* @returns: true if answer to above q is yes
*/
public static boolean look(String[]p,String w)
{
boolean flag=false;
for(int i=0;(i<p.length && !flag);i++)
if (p[i].equals(w))flag=true;
return flag;
}
}//Meth1
[/pre]
>
> a) Work out and document the processes being carried out
> by the method "words"
> in the above class. Your documentation should include
> ude any data used for this purpose.
>
> Tips:
> -----
>
> import java.io.*;
>
> public class TestMeth1
> {
> public static void main(String args[])
> {
> String
> ng
> w1[]={"cast","static","thread","make","void","import"};
> String w2[]={"import","cast","static"};
>
> Meth1 m = new Meth1();
>
> System.out.println(m.words(w1,w2));
>
> }//main
>
>
>
> b) A client has an array of English words. What is
> required to list all those words
> from the array, which come alphabetically after the
> the word "make", and they are to
> appear in alphabetical order.
> For example, given an array of words as shown below:
>
> cast static thread make void import
>
> should produce an array of words:
>
> static thread void
>
> Use inheritance to extend the class "Meth1" to provide
> ide the necessary methods
> which achieves the specified requirement.
>
> Tips:
> -----
>
> //Do inheritance with Task 1 a)
>
> {
> void sortWords(...)
>
> {
> .
> .
> .
> }
>
> void displayAll(...)
>
> {
> .
> .
> .
> }
>
> void displayFrom(String w[], String point)
>
> {
> .//if point exist in String w[], output all words
> words after "make"
> .//else, error message.
> .
> }
> }
>
>
> public class TestTask1b
> {
> public static void main
> {
> Task1b t = new Task1b();
> .
> .
> .
> }
> }
>
> THE END
>
>
For the above run a google on sort algorithms,
sort String array, that should help you sort
the given array and fill in the method
void sortWords(String []words){
}
once words is sorted have another method
/* make sure you pass in the correct array
* that you have just sorted as argument words
* when calling it
*/
private int indexOfMake(String []words){
int i = 0;
for(i = 0; i < words.length; i++){
if(words[i].equals("make")
return i;
}
return i;
}
when you call this you will call
int makeIndex = indexOfMake(words);
run through this array with a for loop and
only add to a new array, the array elements
for which: i > makeIndex;
public String[] retrieveMakeArray(String []words){
int sizeOfNewArray = words.length - makeIndex+1;
String [] newArray = new String[sizeOfNewArray];
int j = 0;
for(int i = makeIndex+1; i < sizeOfNewArray; i++){
newArray[j] = words[i];
j++;
}
return newArray;
}
[pre]
sortedArray = retrieveMakeArray(words);
I think I've pretty much done 70% of your homework.
Ask your prof to credit me, now I gotta get back to
coding significant things.
Spike