Untitled

 avatar
user_8976993604
plain_text
2 years ago
2.8 kB
1
Indexable
Never
package ee.taltech.b_practise.assignment8;

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

public class Filter extends PositivesAndNegatives {

    static List<Integer> positive_numbers = new ArrayList<>();
    static List<Integer> negative_numbers = new ArrayList<>();
    static PositivesAndNegatives object = new PositivesAndNegatives(positive_numbers, negative_numbers);

    //todo A write tests in FilterTest
    //todo B make tests pass
    //todo C make your solution pretty
    // it's up to you how you want to handle null inputs
    // you don't need to modify PositivesAndNegatives object
    // P.S streams don't add much value here

    //todo A begins:
    public static List<Integer> test_1(List<Integer> list){
        list.add(45);
        list.add(null);
        list.add(-34);
        list.add(-562);
        list.add(0);
        list.add(9034);
        return list;
    }

    public static List<Integer> test_2(List<Integer> list){
        list.add(-320);
        list.add(null);
        list.add(-17924);
        list.add(285);
        list.add(-8902);
        list.add(null);
        list.add(59);
        list.add(0);
        list.add(-478);
        return list;
    }

    //todo A ends, todo B begins:

    public static void initial_method(List<Integer> numbers){
        int i = 0;
        while(numbers.size() > 0){
            if(numbers.get(i) == null){
                continue;
            } else if(numbers.get(i) > -1){
                positive_numbers.add(numbers.get(i));
            }else{
                negative_numbers.add(numbers.get(i));
            }
            i++;
        }
    }

    // todo B ends, todo C begins:

    public static void letter_method(List<Integer> numbers){
        numbers.removeAll(null);
        for(Integer i : numbers){
            if (i >= 0) positive_numbers.add(i);
             else negative_numbers.add(i);
             numbers.remove(i);
        }
    }

    /*
     * divides integer input into positives and negatives
     * zero 0, can be treated as positive
     */

    public PositivesAndNegatives filterToPositivesAndNegatives(List<Integer> numbers){
        return new PositivesAndNegatives();
    }

        // todo C ends tests cases begin

    public static void main(String[] args){

        List<Integer> numbers = new ArrayList<>();

        initial_method(test_1(numbers));
        
        object.setPositives(positive_numbers);
        object.setNegatives(negative_numbers);

        System.out.println("The positive elements are: " + object.getPositives());
        System.out.println("The negative elements are: " + object.getNegatives());



    }
}