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/8/logging/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
Java 如果要比较的两个值具有相同的值,如何打印存储在treemap中的值?_Java_Sorting_Treemap - Fatal编程技术网

Java 如果要比较的两个值具有相同的值,如何打印存储在treemap中的值?

Java 如果要比较的两个值具有相同的值,如何打印存储在treemap中的值?,java,sorting,treemap,Java,Sorting,Treemap,如果我输入以下内容: student #1 id number: 1 name: aaa course: cs student#2 id number: 1 name: aaa course: cs 树映射应提示它按id号排序。 然后,它应该这样打印: student id number course aaa 1 cs aaa 1 cs student id number course aaa 1

如果我输入以下内容:

student #1
id number: 1
name: aaa
course: cs

student#2
id number: 1
name: aaa
course: cs
树映射应提示它按id号排序。
然后,它应该这样打印:

student   id number   course
aaa       1           cs
aaa       1           cs
student   id number   course
aaa       1           cs
但就我而言,它看起来是这样的:

student   id number   course
aaa       1           cs
aaa       1           cs
student   id number   course
aaa       1           cs
这是我的密码:

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.TreeMap;

public class studentreport {
    static Scanner j = new Scanner(System.in);
    static Scanner a = new Scanner(System.in);

    public static void main(String[] args) {

        List<String> studentnumberA = new ArrayList<String>();
        List<String> studentnameA = new ArrayList<String>();
        List<String> courseA = new ArrayList<String>();
        List<Double> prelimA = new ArrayList<Double>();
        List<Double> midtermA = new ArrayList<Double>();
        List<Double> finalsA = new ArrayList<Double>();
        List<Double> sumA = new ArrayList<Double>();

        double prelim, midterm, finals;
        String menu, menu2;
        String transaction = null, transaction2 = null, transaction3 = null;
        String studentname = null, course = null, studentnumber = null;

        do {
            System.out.print("\t\t\tDi Natuto University \n\t\t\t    " +
                    "Pililla,Rizal \n\n\t\t\t" +
                    "Main Menu \n\t\tSM\tStudent Maintenance" +
                    "\n\t\tSR\tStudent Report \n\t\tSGR\t" +
                    "Student Grade Report \n\t\tX\tExit \n\n\t\tProcess? ");
            menu = j.nextLine();
            if (menu.equals("x") || menu.equals("X")) {
                System.exit(0);
            }
            if (menu.equals("SM") || menu.equals("sm")) {
                do {
                    System.out.print("Student Number: ");
                    studentnumber = j.nextLine();
                    studentnumberA.add(studentnumber);

                    System.out.print("Student Name: ");
                    studentname = j.nextLine();
                    studentnameA.add(studentname);

                    System.out.print("Course : ");
                    course = j.nextLine();
                    courseA.add(course);

                    System.out.print("Prelim Grade: ");
                    prelim = j.nextDouble();
                    prelimA.add(prelim);

                    System.out.print("Midterm Grade: ");
                    midterm = j.nextDouble();
                    midtermA.add(midterm);

                    System.out.print("Finals Grade: ");
                    finals = j.nextDouble();
                    finalsA.add(finals);
                    j.nextLine();

                    System.out.println("Continue? (Y/N): ");
                    transaction = a.nextLine();

                } while (transaction.equalsIgnoreCase("Y"));
            }

            if (menu.equalsIgnoreCase("sr")) {
                do {
                    System.out
                    .println("\t\t\tDi Natuto University \n\t\t\t" +
                            "Pililla,Rizal \n\n\t\t\tStudent Summary Report" +
                            "\n\n\t\t\tSNo\tStudent no." +
                            "\n\t\t\tSna\tStudent Name \n\t\t\tCo\tCourse" +
                            "\n\t\t\tX\tExit \n\n\t\tProcess? ");
                    menu2 = j.nextLine();
                    System.out.println("\n");
                    if (menu2.equalsIgnoreCase("X")) {
                        System.exit(0);
                    }

                    if (menu2.equalsIgnoreCase("sno")) {

                        String[] array = studentnumberA
                                .toArray(new String[studentnumberA.size()]);
                        String[] array2 = studentnameA
                                .toArray(new String[studentnameA.size()]);
                        String[] array3 = courseA.toArray(new String[courseA
                                                                     .size()]);
                        String[][] storeAllArray = { array, array2, array3 };
                        TreeMap<String, String> map = new TreeMap<String, String>();
                        TreeMap<String, String> map2 = new TreeMap<String, String>();

                        System.out
                        .println("\t\t\t\tDi Natuto University \n\t\t\t\t" +
                                "Pililla,Rizal \n\n\t\t\t\t" +
                                "Student Summary Report \n\n\t\t\tStudent no."
                                + "Student Name\t\tCourse ");
                        for (int i = 0; i < array.length; i++) {
                            map2.put(array[i], array3[i]);
                            map.put(array[i], array2[i]);

                        }
                        for (String key : map.keySet())
                            System.out.println("\t\t\t" + key + "\t\t "
                                    + map.get(key) + "\t\t\t" + map2.get(key));
                        System.out.println("\n");
                    }
                    if (menu2.equalsIgnoreCase("sna")) {
                        String[] array = studentnumberA
                                .toArray(new String[studentnumberA.size()]);
                        String[] array2 = studentnameA
                                .toArray(new String[studentnameA.size()]);
                        String[] array3 = courseA.toArray(new String[courseA
                                                                     .size()]);
                        String[][][] storeAllArray = { { array }, { array2 },
                                { array3 } };
                        TreeMap<String, String> map = new TreeMap<String, String>();
                        TreeMap<String, String> map2 = new TreeMap<String, String>();

                        System.out
                        .println("\t\t\t\tDi Natuto University \n\t\t\t\t" +
                                "Pililla,Rizal \n\n\t\t\t\t" +
                                "Student Summary Report \n\n\t\t\tStudent no."
                                + "   Student Name" + "\tCourse ");
                        for (int i = 0; i < array.length; i++) {
                            map2.put(array2[i], array3[i]);
                            map.put(array2[i], array[i]);

                        }
                        for (String key : map.keySet())
                            System.out.println("\t\t\t" + map.get(key)
                                    + "\t\t " + key + "\t\t" + map2.get(key));
                        System.out.println("\n");
                    }
                    if (menu2.equalsIgnoreCase("co")) {
                        String[] array = studentnumberA
                                .toArray(new String[studentnumberA.size()]);
                        String[] array2 = studentnameA
                                .toArray(new String[studentnameA.size()]);
                        String[] array3 = courseA.toArray(new String[courseA
                                                                     .size()]);
                        TreeMap<String, String> map = new TreeMap<String, String>();
                        TreeMap<String, String> map2 = new TreeMap<String, String>();

                        System.out
                        .println("\t\t\t\tDi Natuto University \n\t\t\t\t" +
                                "Pililla,Rizal \n\n\t\t\t\t" +
                                "Student Summary Report \n\n\t\t\tStudent no."
                                + "   Student Name" + "\tCourse ");
                        for (int i = 0; i < array.length; i++) {
                            map2.put(array3[i], array2[i]);
                            map.put(array3[i], array[i]);

                        }
                        for (String key : map.keySet())
                            System.out.println("\t\t\t" + map.get(key)
                                    + "\t\t " + map2.get(key) + "\t\t" + key);
                        System.out.println("\n");

                    }

                    System.out.print("Continue? (Y/N)");
                    transaction2 = j.nextLine();
                } while (transaction2.equalsIgnoreCase("Y"));
            }
            if (menu.equalsIgnoreCase("sgr")) {

                String[] array = studentnumberA
                        .toArray(new String[studentnumberA.size()]);
                String[] array2 = studentnameA.toArray(new String[studentnameA
                                                                  .size()]);
                String[] array3 = courseA.toArray(new String[courseA.size()]);
                Double[] array4 = prelimA.toArray(new Double[prelimA.size()]);
                Double[] array5 = midtermA.toArray(new Double[midtermA.size()]);
                Double[] array6 = finalsA.toArray(new Double[finalsA.size()]);
                Double[] array7 = sumA.toArray(new Double[sumA.size()]);
                String[][] storeAllArray = { array, array2, array3 };
                TreeMap<Double, String> map = new TreeMap<Double, String>();
                TreeMap<Double, String> map2 = new TreeMap<Double, String>();
                TreeMap<Double, String> map3 = new TreeMap<Double, String>();

                System.out
                .println("\t\t\t\tDi Natuto University \n\t\t\t\t" +
                        "Pililla,Rizal \n\n\t\t\t\t" +
                        "Student Grade Report \n\n\t\t\tStudent no."
                        + "   Student Name"
                        + "\tCourse"
                        + "\t\t\tAverage");

                for (int i = 0; i < array.length; i++) {
                    double sum = (array4[i] + array5[i] + array6[i]) / 3;
                    sumA.add(sum);
                    map.put(array7[i], array[i]);
                    map2.put(array7[i], array2[i]);
                    map3.put(array7[i], array3[i]);

                }
                for (Double key : map.keySet())
                    System.out.println("\t\t\t" + map.get(key) + "\t\t "
                            + map2.get(key) + "\t\t" + map2.get(key) + "\t\t"
                            + key);

                System.out
                .print("\n\n\t\t\tM\t\tMain Menu\n\t\t\tX\t\tExit\nChoice: ");
                transaction3 = j.nextLine();

                if (transaction3.equalsIgnoreCase("X")) {
                    System.out
                    .print("\t\t\t\tDi Natuto University \n\t\t\t\t" +
                            "Pililla,Rizal \n\n\t\t\t\t" +
                            "Thank you for using Di Natuto Grading System...");
                    System.exit(0);
                }
            }
        } while (transaction.equalsIgnoreCase("N")
                || transaction2.equalsIgnoreCase("N")
                || transaction3.equalsIgnoreCase("M"));
    }
}
import java.util.ArrayList;
导入java.util.List;
导入java.util.Scanner;
导入java.util.TreeMap;
公共班学生中心{
静态扫描仪j=新扫描仪(System.in);
静态扫描仪a=新扫描仪(System.in);
公共静态void main(字符串[]args){
List studentnumberA=new ArrayList();
List studentnameA=new ArrayList();
List courseA=new ArrayList();
List prelimA=new ArrayList();
List midtermA=new ArrayList();
List finalsA=new ArrayList();
List sumA=new ArrayList();
双人预赛、期中赛、决赛;
字符串菜单,菜单2;
字符串transaction=null,transaction2=null,transaction3=null;
字符串studentname=null,course=null,studentnumber=null;
做{
System.out.print(“\t\t\tDi Natuto University\n\t\t\t”+
皮利亚,里扎尔\n\n\t\t\t+
“主菜单\n\t\tSM\t学生维护”+
“\n\t\tSR\t学生报告\n\t\tSGR\t”+
“学生成绩报告\n\t\tX\tExit\n\n\t\t过程?”);
menu=j.nextLine();
if(menu.equals(“x”)| | menu.equals(“x”)){
系统出口(0);
}
if(menu.equals(“SM”)| | menu.equals(“SM”)){
做{
系统输出打印(“学号:”);
studentnumber=j.nextLine();
学生编号a.add(学生编号);
系统输出打印(“学生姓名:”);
studentname=j.nextLine();
studentnameA.add(studentname);
系统输出打印(“课程:”);
课程=j.nextLine();
课程a.添加(课程);
系统输出打印(“预调等级:”);
prelim=j.nextDouble();
预备。添加(预备);
系统输出打印(“期中成绩:”);
中期=j.nextDouble();
中期补充(中期);
系统输出打印(“期末成绩:”);
期末考试=j.nextDouble();
最后加上(总决赛);
j、 nextLine();
系统输出打印项次(“是否继续”);
事务=a.nextLine();
}而(交易同等信号情况(“Y”);
}
if(菜单等信号情况(“sr”)){
做{
系统输出
.println(“\t\t\tDi Natuto University\n\t\t\t”+
Piilla,Rizal\n\n\t\t\t学生总结报告+
“\n\n\t\t\t\t学生号”+
“\n\t\t\tSna\t学生名\n\t\t\tCo\t课程”+
“\n\t\t\tX\tExit\n\n\t\t过程?”);
menu2=j.nextLine();
System.out.println(“\n”);
if(menu2.equalsIgnoreCase(“X”)){
系统出口(0);
}
if(menu2.equalsIgnoreCase(“sno”)){
字符串[]数组=studentnumberA
.toArray(新字符串[studentnumberA.size()]);
字符串[]array2=studentnameA
.toArray(新字符串[studentnameA.size()]);
字符串[]数组3=courseA.toArray(新字符串[courseA
.size());
字符串[][]storeAllArray={array,array2,array3};
TreeMap map=newtreemap();
TreeMap map2=新的TreeMap();
系统输出
.println(“\t\t\t\tDi Natuto University\n\t\t\t\t”+
皮利亚,里扎尔\n\n\t\t\t\t+
“学生总结报告\n\n\t\t\t学生编号。”
+“学生姓名\t\t课程”);
for(int i=0;i        studentnumber=j.nextLine();
        studentnumberA.add(studentnumber);
System.out.println("\t\t\t"+map.get(key)+ "\t\t "+map2.get(key)+"\t\t"+map2.get(key)+"\t\t"+key);
public static void printStudent(String id, String name, String course, int key) {
   System.out.println("\t\t\t"+ id + "\t\t "+ name +"\t\t"+ course +"\t\t" + key);
}
printStudent(map.get(key), map2.get(key), map2.get(key), key);