1. Use the wordList to provide data for the following program. Create three arra
ID: 3798197 • Letter: 1
Question
1. Use the wordList to provide data for the following program. Create three arrayLists named smallWords, medWords, and largeWords. Parse through the array, and place the words that are 4 letters or less in to the smallWords ArrayList. Words between 5 and 9 letters are placed into the medWords list. Words larger than 9 letters are placed into the largeWords list. Once the words are separated, print the size() of each arrayList
2. Create a class called Drywall that holds the length, width, and height for a room. Include a method in class Drywall that calculates the number of sheets needed to drywall this room. A 4x8 drywall sheet covers 32 sq feet. Round up the sheets to a whole number with no decimals . Create an array of 4 different rooms. Total up the total number of drywall sheets needed for the 4 rooms
Explanation / Answer
Hi, I have answered Q1.
Please repost other in separate post.
Please let me know in case of any issue.
import java.util.ArrayList;
public class ArrayListTest {
public static void main(String[] args) {
// we have given wordList
ArrayList<String> wordList = new ArrayList<>();
// adding some words
wordList.add("Ok");
wordList.add("Pravesh");
wordList.add("Apple");
wordList.add("Ball");
wordList.add("Cat");
wordList.add("A");
wordList.add("Lowest");
wordList.add("Average");
wordList.add("Grabage");
wordList.add("Umberalla");
wordList.add("September Month");
wordList.add("yes");
wordList.add("Love");
wordList.add("I love you");
// creating three ArrayList
ArrayList<String> smallWords = new ArrayList<>();
ArrayList<String> medWords = new ArrayList<>();
ArrayList<String> largeWords = new ArrayList<>();
for(String word : wordList){
if(word.length() <= 4)
smallWords.add(word);
else if(word.length() <= 9)
medWords.add(word);
else
largeWords.add(word);
}
System.out.println("Size of samll words: "+smallWords.size());
System.out.println("Size of medium words: "+medWords.size());
System.out.println("Size of large words: "+largeWords.size());
}
}
/*
Sample run:
Size of samll words: 6
Size of medium words: 6
Size of large words: 2
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.