Question

In: Computer Science

Create a static method with the appropriate inputs and outputs. Call each of them in the...

Create a static method with the appropriate inputs and outputs. Call each of them in the main method.

Write a method called unique() which takes in a List and returns true if all the items in the List are unique. All the items are unique if none of them are the same.Return false otherwise.

Please do this in Java.

Solutions

Expert Solution

import java.util.ArrayList;
import java.util.List;

public class UniqiueCheck {
    public static boolean unique(List list){
        for(int i = 0;i<list.size();i++){
            for(int j = i+1;j<list.size();j++){
                if(list.get(i).equals(list.get(j))){
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        list1.add(4);
        System.out.println(unique(list1));

        List<Integer> list2 = new ArrayList<>();
        list2.add(1);
        list2.add(2);
        list2.add(1);
        list2.add(4);
        System.out.println(unique(list2));
    }
}

true
false

public static boolean unique(List list){
    for(int i = 0;i<list.size();i++){
        for(int j = i+1;j<list.size();j++){
            if(list.get(i).equals(list.get(j))){
                return false;
            }
        }
    }
    return true;
}


Related Solutions

Create a static method with the appropriate inputs and outputs. Call each of them in the...
Create a static method with the appropriate inputs and outputs. Call each of them in the main method. Write a method called stringToListOfWords() which takes in a String converts it into a list of words. We assumes that each word in the input string is separated by whitespace.3 2Use the equals() method. 3The split() method of String can split an input up along a provided special string called a regular expression or regex. A regex is much like a code...
Create a static method with the appropriate inputs and outputs. Call each of them in the...
Create a static method with the appropriate inputs and outputs. Call each of them in the main method. Write a method called removeAllInstances() which takes in a List and item4 . The method then proceeds to remove each item in the list that matches the given item. For example, if the method is passed the List [1, 4, 5, 6, 5, 5, 2] and the Integer 5, the method removes all 5’s from the List. The List then becomes [1,...
Create a static method with the appropriate inputs and outputs. Call each of them in the...
Create a static method with the appropriate inputs and outputs. Call each of them in the main method. Write a method called isPermutaion() which takes in two List objects which contain the same types. It returns true if the Lists are permutations of each other and false if not. Two lists are permutations if they contain the same elements, including the same number of duplicates, but they don’t have to contain the elements in the same order. For example, [1,2,...
Create a static method with the appropriate inputs and outputs. Call each of them in the...
Create a static method with the appropriate inputs and outputs. Call each of them in the main method. Write a method named allMultiples() which takes in a List of integers and an int. The method returns a new List of integers which contains all of the numbers from the input list which are multiples of the given int. For example, if the List is [1, 25, 2, 5, 30, 19, 57, 2, 25] and 5 was provided, the new list...
Explain the inputs (and outputs if you know them) of the following Excel functions: • Norm.S.Dist()....
Explain the inputs (and outputs if you know them) of the following Excel functions: • Norm.S.Dist(). • Norm.Inv(). • T.Dist().
Objectives • Use the static methods and static fields. •Use the method-call/return mechanism. • Use the...
Objectives • Use the static methods and static fields. •Use the method-call/return mechanism. • Use the random-number generation. • Overload methods. Problem Specification Write a program that lets a user play "Rock, Paper, Scissors" against the computer or computer against computer. In user-computer game, the program should ask the user to choose one of the three choices, and then the computer randomly picks one (without knowing what the user has chosen). For this problem, the user should be asked to...
Write a static method startsWith that inputs two Strings and returns a boolean. If the first...
Write a static method startsWith that inputs two Strings and returns a boolean. If the first input starts with the substring that is the second input, then the method returns true; otherwise, it returns false. For example, startsWith( "radar installation", "rad" ) returns true startsWith( "radar installation", "installation" ) returns false startsWith( "radar installation", "" ) returns true startsWith( "", "a" ) returns false startsWith( "", "" ) returns true
Write a static method endsWith that inputs two Strings and returns a boolean. If the first...
Write a static method endsWith that inputs two Strings and returns a boolean. If the first input ends with the substring that is the second input, then the method returns true; otherwise, it returns false. For example, endsWith( "radar installation", "rad" ) returns false endsWith( "radar installation", "installation" ) returns true endsWith( "radar installation", "" ) returns true endsWith( "", "a" ) returns false endsWith( "", "" ) returns true
Create a detailed process flowchart that includes process inputs, process outputs, activities, activity times, processing and...
Create a detailed process flowchart that includes process inputs, process outputs, activities, activity times, processing and labor requirements for a fictional retail chain of coffee shops. Capacity analysis of the process, including the strategies used to address expected customer demand. Suggested metrics used to measure the process performance. Identify the process problem and make suggestions on how the process can be improved
Draw a block diagram of an elevator controller. Clearly identify inputs and outputs of each block....
Draw a block diagram of an elevator controller. Clearly identify inputs and outputs of each block. Assume the elevator has 4 floors. Draw a state diagram for the elevator controller and briefly explain what the input, state variables, and ouput represent.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT