Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java d到arraylist的末尾 对于(int k=0;k_Java_Sorting_Double_Multidimensional Array - Fatal编程技术网

Java d到arraylist的末尾 对于(int k=0;k

Java d到arraylist的末尾 对于(int k=0;k,java,sorting,double,multidimensional-array,Java,Sorting,Double,Multidimensional Array,}您应该实现一个对象,该对象保存arraylist(内部)中的所有值。然后,您可以轻松实现检查推荐分数的Comparable,这听起来应该使用数据库,而不是对象的数组列表来完成……写得不好,请添加更多信息。它们是什么类型的。所有Objects?是否要将外部Arraylist与内部Arraylist中的对象进行排序?Post code。。很难从你的问题中看出你想要什么 public static ArrayList<Double> attRanking(ArrayList<Dou

}

您应该实现一个对象,该对象保存arraylist(内部)中的所有值。然后,您可以轻松实现检查
推荐分数的
Comparable

这听起来应该使用数据库,而不是对象的数组列表来完成……写得不好,请添加更多信息。它们是什么类型的。所有
Object
s?是否要将外部Arraylist与内部Arraylist中的对象进行排序?Post code。。很难从你的问题中看出你想要什么
public static ArrayList<Double> attRanking(ArrayList<Double> attRank){

    ArrayList<Double> attWeight = new ArrayList<>();
    double weight;

    /*Loops through the rankings given in the questionnaire 
     * and sets a new number for better recommendation accuracy */
    for(int i = 0; i < attRank.size();i++){

        if(attRank.get(i) == 1){
            attRank.set(i, 7.0);
        }
        else if(attRank.get(i) == 2){
            attRank.set(i, 6.0);
        }
        else if(attRank.get(i) == 3){
            attRank.set(i, 5.0);
        }
        else if(attRank.get(i) == 4){
            attRank.set(i, 4.0);
        }
        else if(attRank.get(i) == 5){
            attRank.set(i, 3.0);
        }
        else if(attRank.get(i) == 6){
            attRank.set(i, 2.0);
        }           
        else if(attRank.get(i) == 0){
            attRank.set(i, 1.0);
        }
    }

            //Loop through the ranked values and assign a weighting to each attribute
    for(int j = 0; j < attRank.size(); j++){
        weight = (attRank.get(j))/28;
        attWeight.add(weight);
    }

    for(int k = 0; k < attWeight.size();k++){
        System.out.println(attWeight.get(k));
    }
    return attWeight;
}

public static ArrayList<ArrayList> valuePoints(ArrayList<ArrayList> valuePoints){
        //DataRetrievalImpl database = new DataRetrievalImpl();
        ArrayList<ArrayList> holiday = new ArrayList<>();

        //test info
        ArrayList<String> test = new ArrayList<>();
        test.add("stuff1");
        test.add("stuff2");
        test.add("stuff3");
        test.add("stuff4");
        test.add("stuff5");
        test.add("stuff6");
        holiday.add(test);
        ArrayList<String> test1 = new ArrayList<>();
        test1.add("stuff11");
        test1.add("stuff12");
        test1.add("stuff13");
        test1.add("stuff14");
        test1.add("stuff15");
        test1.add("stuff16");
        holiday.add(test1);


        ArrayList<ArrayList> holidayScore = new ArrayList<>(); // creates new arraylist to hold the 6 attributes and their value points to be used in recommendation score
        //database information
        /*boolean condition = false;
        String[] select = null;
        String[] from = null;
        String[] where = null;
        holiday = database.getData(condition, select, from, where);*/

        //Loops through the holiday arraylist which contains all the holidays and adds the attributes that we need to the new one along with default points
        for(int i = 0; i < holiday.size(); i++){
            holidayScore.add(new ArrayList());
            holidayScore.get(i).add(holiday.get(i).get(0));
            holidayScore.get(i).add("0");
            holidayScore.get(i).add(holiday.get(i).get(1));
            holidayScore.get(i).add("0");
            holidayScore.get(i).add(holiday.get(i).get(2));
            holidayScore.get(i).add("0");
            holidayScore.get(i).add(holiday.get(i).get(3));
            holidayScore.get(i).add("0");
            holidayScore.get(i).add(holiday.get(i).get(4));
            holidayScore.get(i).add("0");
            holidayScore.get(i).add(holiday.get(i).get(5));
            holidayScore.get(i).add("0");
        }

        //Loops through the holidayScore arraylist checking the attributes against the valuePoints array list and 
        //modifying the value points where the two attribute values are equivalent in both arraylists
        //each if statement checks that each attrbute value is equivalent, successful matches record the points from valuePoints into holidayScore
        for(int j = 0; j < holidayScore.size(); j++){

            if(holidayScore.get(j).get(0) == valuePoints.get(j).get(0)){
                holidayScore.get(j).set(1, valuePoints.get(j).get(1));
            }

            if(holidayScore.get(j).get(2) == valuePoints.get(j).get(2)){
                holidayScore.get(j).set(3, valuePoints.get(j).get(3));
            }

            if(holidayScore.get(j).get(4) == valuePoints.get(j).get(4)){
                holidayScore.get(j).set(5, valuePoints.get(j).get(5));
            }

            if(holidayScore.get(j).get(6) == valuePoints.get(j).get(6)){
                holidayScore.get(j).set(7, valuePoints.get(j).get(7));
            }

            if(holidayScore.get(j).get(8) == valuePoints.get(j).get(8)){
                holidayScore.get(j).set(9, valuePoints.get(j).get(9));
            }

            if(holidayScore.get(j).get(10) == valuePoints.get(j).get(10)){
                holidayScore.get(j).set(11, valuePoints.get(j).get(11));
            }  
        }

        System.out.println(holiday);
        System.out.println("----------------------------------------------------");
        System.out.println(holidayScore);
        return holidayScore;
}

public static void recommendation(ArrayList<Double> weightedAttr, ArrayList<ArrayList> holidayScores){

        //each variable holds the current value points for that attribute value
        double countryValue;
        double durationValue;
        double accTypeValue;
        double holSubTypeValue;
        double weatherValue;
        double pricePPValue;
        double recScore;

        //Loops through the holidayScores arraylist convert the value points into double which is multiplied by the appropriate attribute weighting
        //this gives a decimal score for each attribute which is summed up for the final recommendation score and added to the end of the arraylist
        for(int k = 0; k < holidayScores.size(); k++){
            countryValue = Double.parseDouble(holidayScores.get(k).get(1).toString());
            durationValue = Double.parseDouble(holidayScores.get(k).get(3).toString());
            accTypeValue = Double.parseDouble(holidayScores.get(k).get(5).toString());
            holSubTypeValue = Double.parseDouble(holidayScores.get(k).get(7).toString());
            weatherValue = Double.parseDouble(holidayScores.get(k).get(9).toString());
            pricePPValue = Double.parseDouble(holidayScores.get(k).get(11).toString());
            recScore = (countryValue * weightedAttr.get(0));
            recScore = recScore + (durationValue * weightedAttr.get(1));
            recScore = recScore + (accTypeValue * weightedAttr.get(2));
            recScore = recScore + (holSubTypeValue * weightedAttr.get(3));
            recScore = recScore + (weatherValue * weightedAttr.get(4));
            recScore = recScore + (pricePPValue * weightedAttr.get(5));
            holidayScores.get(k).add(recScore);
        }

        System.out.println(holidayScores);
}