Need help coding this List. Lists are a lot like arrays, but you’ll be using get, set, add, size and the like instead of the array index operators [].
package list.exercises;
import java.util.List;
public class ListExercises {
/**
* Counts the number of characters in total across all strings in the supplied list;
* in other words, the sum of the lengths of the all the strings.
* @param l a non-null list of strings
* @return the number of characters
*/
public static int countCharacters(List<String> l) {
return 0;
}
/**
* Splits a string into words and returns a list of the words.
* If the string is empty, split returns a list containing an empty string.
*
* @param s a non-null string of zero or more words
* @return a list of words
*/
public static List<String> split(String s)
{
return null;
}
/**
* Returns a copy of the list of strings where each string has been
* uppercased (as by String.toUpperCase).
*
* The original list is unchanged.
*
* @param l a non-null list of strings
* @return a list of uppercased strings
*/
public static List<String> uppercased(List<String> l) {
return null;
}
/**
* Returns true if and only if each string in the supplied list of strings
* starts with an uppercase letter. If the list is empty, returns false.
*
* @param l a non-null list of strings
* @return true iff each string starts with an uppercase letter
*/
public static boolean allCapitalizedWords(List<String> l) {
return false;
}
/**
* Returns a list of strings selected from a supplied list, which contain the character c.
*
* The returned list is in the same order as the original list, but it omits all strings
* that do not contain c.
*
* The original list is unmodified.
*
* @param l a non-null list of strings
* @param c the character to filter on
* @return a list of strings containing the character c, selected from l
*/
public static List<String> filterContaining(List<String> l, char c) {
return null;
}
/**
* Inserts a string into a sorted list of strings, maintaining the sorted property of the list.
*
* @param s the string to insert
* @param l a non-null, sorted list of strings
*/
public static void insertInOrder(String s, List<String> l) {
}
}
import java.util.ArrayList;
import java.util.List;
public class ListExercises {
/**
* Counts the number of characters in total across all strings in the supplied list;
* in other words, the sum of the lengths of the all the strings.
* @param l a non-null list of strings
* @return the number of characters
*/
public static int countCharacters(List<String> l) {
return l.size();
}
/**
* Splits a string into words and returns a list of the words.
* If the string is empty, split returns a list containing an empty string.
*
* @param s a non-null string of zero or more words
* @return a list of words
*/
public static List<String> split(String s) {
List<String> list = new ArrayList<>();
String[] arr = s.split(" ");
for ( String ss : arr) {
list.add(ss);
}
return list;
}
/**
* Returns a copy of the list of strings where each string has been
* uppercased (as by String.toUpperCase).
*
* The original list is unchanged.
*
* @param l a non-null list of strings
* @return a list of uppercased strings
*/
public static List<String> uppercased(List<String> l) {
List<String> list = new ArrayList<>();
for (String str : l) {
list.add(str.toUpperCase());
}
return list;
}
/**
* Returns true if and only if each string in the supplied list of strings
* starts with an uppercase letter. If the list is empty, returns false.
*
* @param l a non-null list of strings
* @return true iff each string starts with an uppercase letter
*/
public static boolean allCapitalizedWords(List<String> l) {
boolean isAllCaps = true;
for (String str : l) {
for (int i=0; i<str.length(); i++)
{
if (Character.isLowerCase(str.charAt(i)))
{
isAllCaps = false;
break;
}
}
}
return isAllCaps;
}
/**
* Returns a list of strings selected from a supplied list, which contain the character c.
*
* The returned list is in the same order as the original list, but it omits all strings
* that do not contain c.
*
* The original list is unmodified.
*
* @param l a non-null list of strings
* @param c the character to filter on
* @return a list of strings containing the character c, selected from l
*/
public static List<String> filterContaining(List<String> l, char c) {
List<String> list = new ArrayList<>();
for (String str : l) {
if (str.indexOf(c) != -1) {
list.add(str);
}
}
return list;
}
/**
* Inserts a string into a sorted list of strings, maintaining the sorted property of the list.
*
* @param s the string to insert
* @param l a non-null, sorted list of strings
*/
public static void insertInOrder(String s, List<String> l) {
l.add(s);
java.util.Collections.sort(l);
}
}
Need help coding this List. Lists are a lot like arrays, but you’ll be using get,...
/** * Returns true if and only if each string in the supplied list of strings * starts with an uppercase letter. If the list is empty, returns false. * * @param l a non-null list of strings * @return true iff each string starts with an uppercase letter */ public static boolean allCapitalizedWords(List<String> l) { } Here are the tests: @Test public void testAllCapitalizedWordsEmptyList() { assertFalse(ListExercises.allCapitalizedWords(Arrays.asList()));...
Objectives
Problem solving using arrays and ArrayLists. Abstraction.
Overview
The diagram below illustrates a banner constructed from
block-letters of size 7. Each block-letter is
composed of 7 horizontal line-segments of width 7 (spaces
included):
SOLID
as in block-letters F, I, U, M, A, S and the
blurb RThere are six distinct line-segment
types:
TRIPLE
as in block-letter M
DOUBLE
as in block-letters U, M, A
LEFT_DOT
as in block-letters F, S
CENTER_DOT as
in block-letter...
I need the following merge-sort assignment completed using the "ArrayList<Comparable>" (the part I'm really stuck on) with comments: import java.util.ArrayList; public class Mergesort { /** * Sorts list given using the mergesort algorithm * @param list the list to be sorted * @param first the index of the first element of the list to be sorted * @param last the index of the last element of the list to be sorted */ public static void mergesort(ArrayList<Comparable> list, int first, int...
Hi I really need help with the methods for this lab for a computer science class. Thanks Main (WordTester - the application) is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes. Word The Word class represents a single word. It is immutable. You have been provided...
Need Help Using Java programming only import java.util.ArrayList; //Import anything you need here public class Dictionary { // Declare any variables you feel necessary here public Dictionary(/*DO NOT PUT ANY PARAMETERS HERE!*/) { // Initialise those variables } /*** * @return number of terms currently in the dictionary hint: starts at 0 when * there are no terms */ public int numberOfTerms() { return 0; } /*** ...
For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...
Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all others intact and follow similar guidelines. The methods that need to be changed are in the code below. - Rewrite the indexOf() method. Remove the existing recursive implementation of the method, and replace it with one that uses iteration instead. - Rewrite the isPrefix() method so that it uses iteration. Remove the existing recursive implementation of the method, and replace it with one that...
I need help with this. I need to create the hangman game using char arrays. I've been provided with the three following classes to complete it. I have no idea where to start. HELP!! 1. /** * This class contains all of the logic of the hangman game. * Carefully review the comments to see where you must insert * code. * */ public class HangmanGame { private final Integer MAX_GUESSES = 8; private static HangmanLexicon lexicon = new HangmanLexicon();...
Given java code is below, please use it!
import java.util.Scanner;
public class LA2a {
/**
* Number of digits in a valid value sequence
*/
public static final int SEQ_DIGITS = 10;
/**
* Error for an invalid sequence
* (not correct number of characters
* or not made only of digits)
*/
public static final String ERR_SEQ = "Invalid
sequence";
/**
* Error for...
Java/LinkedList Need help with a few of the TODO parts, more info below in comments in bold. Thanks, package lab4; import java.util.IdentityHashMap; public class IntNode implements Cloneable { private int data; private IntNode next; public IntNode(int d, IntNode n) { data = d; next = n; } public IntNode getNext() { return next; } /// Override methods from Object @Override ...