subject

java programming

9.9 ch 9, part 2: arraylist searching

import java. util. arraylist;

public class arraylistset {

/**
* searches through the arraylist arr, from the first index to the last, returning an arraylist
* containing all the indexes of strings in arr that match string s. for this method, two strings,
* p and q, match when p. equals(q) returns true or if both of the compared references are null.
*
* @param s the string to search for.
* @param arr the arraylist of string to search.
* @return an arraylist of the indexes in arr that match s. the arraylist will be ordered from
* the smallest index to the largest. if arr is null, the method will return null.
*/
public static arraylist findexact(string s, arraylist arr) {
return null;
}

/**
* searches through the arraylist arr, from the first index to the last, returning an arraylist
* containing all the indexes of strings in arr that contains string s. for this method, a
* strings p contains q when p. contains(q) returns true or if both of the compared references are null.
*
* @param s the string to search for.
* @param arr the arraylist of string to search.
* @return an arraylist of the indexes in arr that contains s. the arraylist will be ordered from
* the smallest index to the largest. if arr is null, the method will return null.
*/
public static arraylist findcontains(string s, arraylist arr) {
return null;
}

/**
* adds string s to the end of the arraylist arr if and only if arr does not already have an
* element that matches s.
*
* do not duplicate code! use your findexact method to check if arr contains s.
*
* @param s the string to add (if not already in arr).
* @param arr the arraylist in which to s (if a string with the same contents is not already in
* arr).
* @return the number of times that s is found in arr after attempting to adding s. if arr is null,
* return -1.
*/
public static int adduniquestring(string s, arraylist arr) {
return -42;
}

}

import java. util. arraylist;
import java. util. arrays;

public class testarraylistset {

public static boolean testfindexact() {
system. out. println("starting ");
//test 1
{
arraylist ret =
arraylistset. findexact("foo", new arraylist(arrays. aslist("foo","bar","foo";
arraylist exp = new arraylist(arrays. aslist(0, 2));
if(! ret. equals(exp)) {
system. out. println("test 1 failed! ");
system. out. println("returned: " + ret);
system. out. println("expected: " + exp);
return false;
}
}
system. out. println(" testfindexact");
return true;
}

public static boolean testfindcontains() {
system. out. println("starting ");
//test 1
{
arraylist ret =
arraylistset. findcontains("o", new arraylist(arrays. aslist("foo","bar","foo";
arraylist exp = new arraylist(arrays. aslist(0, 2));
if(! ret. equals(exp)) {
system. out. println("test 1 failed! ");
system. out. println("returned: " + ret);
system. out. println("expected: " + exp);
return false;
}
}
system. out. println(" testfindcontains");
return true;
}

public static boolean testadduniquestring() {
system. out. println("starting ");
//test 1
{
arraylist arr = new arraylist(arrays. aslist("a","b","c"));
arraylist exp = new arraylist(arr);
exp. add("d");
int retindex = arraylistset. adduniquestring("d", arr);
int expindex = 1;
if(! arr. equals(exp) || retindex ! = expindex) {
system. out. println("test 1 failed! ");
system. out. println("returned value: " + retindex + "; expected " + expindex);
system. out. println("list after: " + arr);
system. out. println("expected: " + exp);
return false;
}
}
//test 2
{
arraylist arr = new arraylist(arrays. aslist("a","b","b","c"));
arraylist exp = new arraylist(arr);
int retindex = arraylistset. adduniquestring("b", arr);
int expindex = 2;
if(! arr. equals(exp) || retindex ! = expindex) {
system. out. println("test 2 failed! ");
system. out. println("returned value: " + retindex + "; expected " + expindex);
system. out. println("list after: " + arr);
system. out. println("expected: " + exp);
return false;
}
}
system. out. println(" testadduniquestring");
return true;
}

public static void main(string[] args) {
testfindexact();
testfindcontains();
testadduniquestring();
}

}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:00
Your task this week is to write a very simple spam classifier in python. it will classify messages as either spam (unwanted) or ham (wanted). the program will have a set of spam_words, words that are known to appear in spam messages. that set is included in the template file spam.pypreview the document. you will also define a spam threshold which reflects the allowed percentage of spam words in the message. you'll compute a 'spam indicator', which is the ratio of spam words to the total number of unique words in the message. if the spam indicator exceeds the spam threshold, the message is classified as spam. otherwise it is classified as ham. we'll assume that the spam threshold is a constant and has a value of 0.10. your program will prompt the user for a message and then will print the corresponding spam indicator with two decimal digits and the corresponding classification (spam or ham). the program will be case insensitive. the spam words are detected whether they are in lower case or upper case or mixed case. each word, spam or not, is counted once (even if it appears multiple times in the message.) the program will remove punctuation from the message before identifying the words and computing the spam indicator. for example '! ' must be identified as the spam word 'now'.
Answers: 3
question
Computers and Technology, 23.06.2019 00:20
The open systems interconnection (osi) reference model: defines standards for many aspects of computing and communications within a network. is a generic description for how computers use multiple layers of protocol rules to communicate across a network. defines standards for wireless local area network (wlan) communication protocols. details the advantages and disadvantages of various basic network cabling options.
Answers: 1
question
Computers and Technology, 23.06.2019 17:30
Write pseudocode to represent the logic of a program that allows the user to enter a value. the program multiplies the value by 10 and outputs the result.
Answers: 1
question
Computers and Technology, 23.06.2019 23:30
A. in packet tracer, only the server-pt device can act as a server. desktop or laptop pcs cannot act as a server. based on your studies so far, explain the client-server model.
Answers: 2
You know the right answer?
java programming

9.9 ch 9, part 2: arraylist searching

import java. util. a...
Questions
question
Social Studies, 20.07.2019 09:00
question
Physics, 20.07.2019 09:00
Questions on the website: 13722363