Question

In: Computer Science

Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that...

Java

1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that removes all of the strings of even length from the list.

2. Given the following Vehicle interface and client program in the Car class:

public interface Vehicle{

public void move();

}

public class Car implements Vehicle{

public static void main(String args[])

Vehicle v = new Vehicle(); // vehicle declaration

}

The above declaration is valid? True or False?

3. Java permits a class to implement only one interface? True or false

4. The Comparable interface enables the comparison of objects in Java? True or false

Solutions

Expert Solution

Answer 1:

import java.util.ArrayList;

public class TestRemoveEvenLength {
        public static void main(String[] args) {
                ArrayList<String>list = new ArrayList<>();
                list.add("Uday");
                list.add("Remove");
                list.add("ABC");
                list.add("Test");
                list.add("Testw");
                
                System.out.println(list);
                removeEvenLength(list);
                System.out.println(list);
        }

        private static void removeEvenLength(ArrayList<String> list) {
                ArrayList<String>res = new ArrayList<>();
                for(String x:list) {
                        if(x.length() % 2 == 0)
                                res.add(x);
                }
                list.removeAll(res);
                
        }
}

Answer 2:

The above declaration is valid? False
as we missed overriding the move in Car
Java permits a class to implement only one interface? false

we can implement any number of interface

The Comparable interface enables the comparison of objects in Java?
True

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME


Related Solutions

Given two ArrayLists of Strings (ArrayList<String>), write a Java method to return the higher count of...
Given two ArrayLists of Strings (ArrayList<String>), write a Java method to return the higher count of the characters in each ArrayList.  For example, if list1 has strings (“cat, “dog”, “boat”, “elephant”) and list 2 has strings (“bat”, “mat”, “port”, “stigma”), you will return the value 18.  The list 1 has 18 characters in total for all its strings combined and list2 has 16 characters for all of its strings combined.  The higher value is 18. If the character count is the same, you...
java/ netbeans Write a recursive method smallestNumber which takes an ArrayList of Integers as input and...
java/ netbeans Write a recursive method smallestNumber which takes an ArrayList of Integers as input and returns the smallest number in the array. You can use a helper method if needed. Write a main method that asks the user for a series of numbers, until the user enters a period. Main should create an ArrayList of these Integers and call smallestNumber to find the smallest number and print it. Compile and test your code in NetBeans and then on Hackerrank.
Code in Java Write a recursive method smallestNumber which takes an ArrayList of Integers as input...
Code in Java Write a recursive method smallestNumber which takes an ArrayList of Integers as input and returns the smallest number in the array. You can use a helper method if needed. Write a main method that asks the user for a series of numbers, until the user enters a period. Main should create an ArrayList of these Integers and call smallestNumber to find the smallest number and print it. Input Format A series of integers Constraints None Output Format...
A Java question. Write the class Staff. It contains methods that manipulate an ArrayList of Strings...
A Java question. Write the class Staff. It contains methods that manipulate an ArrayList of Strings representing the names of staff members. The constructor takes an ArrayList of String names as a parameter. In addition to the constructor, you need to implement the following methods The methods 1. public boolean equals(Staff other) - Determines if the other Staff contains all the same elements in the same order as this Staff 2. public boolean sameContents(Staff other) - Determines if the other...
I am trying to create a method in JAVA that takes in an ArrayList and sorts...
I am trying to create a method in JAVA that takes in an ArrayList and sorts it by the requested "amenities" that a property has. So if someone wants a "pool" and "gym" it would show all members of the array that contain a "pool" and "gym". It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to use the stub class below. You can edit it...
Java Programming CS 209 Data Structure 1. Create a method that takes an ArrayList of String...
Java Programming CS 209 Data Structure 1. Create a method that takes an ArrayList of String and returns a copy of that ArrayList with no duplicates. The relative ordering of elements in the new ArrayList should be the same. Sample Input: {"qwerty", "asdfgh", "qwer", "123", "qwerty", "123", "zxcvbn", "asdfgh"} Sample Output: {"qwerty", "asdfgh", "qwer", "123", "zxcvbn"}
I am trying to create a method in JAVA that takes in an ArrayList<Property> and filters...
I am trying to create a method in JAVA that takes in an ArrayList<Property> and filters it by the requested price range that a property has. So if someone wants a property between the value of 10(min) and 20(max) it would show all members of the array that meet those conditions.. It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to use the stub class below....
I am trying to create a method in JAVA that takes in an ArrayList<Property> and sorts...
I am trying to create a method in JAVA that takes in an ArrayList<Property> and sorts it by the amount of "reviews" that a property has in increasing order. So the most reviews first. So each listing in the array would contain a different number of reviews, and they should be sorted based on that value. It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to...
Write a Java program that takes an ArrayList<Integer>,  adds k copies of it at the end, and...
Write a Java program that takes an ArrayList<Integer>,  adds k copies of it at the end, and returns the expanded ArrayList.  The total size will be (k+1) * n.   public ArrayList<Integer> makeCopies(ArrayList<Integer>, int k) { } Example: ArrayList<Integer> has (3,7,4) and k = 2, then the returned, expanded ArrayList will have (3,7,4,3,7,4,3,7,4).  The total size is (k+1)*n = (2+1)*3= 9.
Write a static method called "evaluate" that takes a string as a parameter
In Java language  Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the expression evaluates to. The method MUST use a stack...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT