Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.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 y) ); } 公共静态void sortStack(){ 公共堆栈排序(堆栈a){ a、 排序(新比较器()); 公共整数比较(整数contID1,整数ContID2){ 返回contID2.compare(contID1); } }); 返回a; } } }_Java_Input_Constructor - Fatal编程技术网

Java y) ); } 公共静态void sortStack(){ 公共堆栈排序(堆栈a){ a、 排序(新比较器()); 公共整数比较(整数contID1,整数ContID2){ 返回contID2.compare(contID1); } }); 返回a; } } }

Java y) ); } 公共静态void sortStack(){ 公共堆栈排序(堆栈a){ a、 排序(新比较器()); 公共整数比较(整数contID1,整数ContID2){ 返回contID2.compare(contID1); } }); 返回a; } } },java,input,constructor,Java,Input,Constructor,我喜欢做的是调用E2.userInput中的'name',并将其放在Main的输出中 我需要userInput中的所有这些项都可以在Main中看到 接下来我需要关于堆栈排序的帮助,我没有为contID创建rand,但是在创建用户时会这样做。我喜欢在创建贡献者之后进行排序(放入堆栈或链表中,但仍然不确定哪一个是最好的) 提前感谢(是的,这是大学课程) public class W_CS230_Main { /** * @param args the command line arguments

我喜欢做的是调用E2.userInput中的'name',并将其放在Main的输出中

我需要userInput中的所有这些项都可以在Main中看到

接下来我需要关于堆栈排序的帮助,我没有为contID创建rand,但是在创建用户时会这样做。我喜欢在创建贡献者之后进行排序(放入堆栈或链表中,但仍然不确定哪一个是最好的)

提前感谢(是的,这是大学课程)

public class W_CS230_Main {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws IOException {


    String content = new String();
    int count=1;
    File file2 = new File("/Users/kilown/Downloads/contributors.csv");
    LinkedList<String> list = new LinkedList<String>();

        try {
            Scanner sc = new Scanner(new FileInputStream(file2));
        while (sc.hasNextLine()){
            content = sc.nextLine();
            list.add(content);
            }
        sc.close();
            }catch(FileNotFoundException fnf){
                    fnf.printStackTrace();
            }
        catch (Exception e) {
                e.printStackTrace();
                System.out.println("\nProgram terminated Safely...");
            }

        Collections.reverse(list);
        Iterator i = list.iterator();
            while (i.hasNext()) {
            System.out.print( (count++) );
            System.out.println(i.next());
            System.out.println("\n");
}




    Scanner in = new Scanner (System.in);    
        int choice;


           System.out.println("\n");
           System.out.println("Welcome User: ");
           System.out.println("Please select your option: ");
           System.out.println("1: Display current list of Contributors: ");
           System.out.println("2: Enter new Contributor: ");
           System.out.println("3: Save File: ");
           System.out.println("4: NDY Pop: ");
           System.out.println("5: NDY (Not Developed Yet)");
           System.out.println("6: NDY (Not Developed Yet)");
           System.out.println("7: Exit: ");
           System.out.println("\n");
           // System.out.println("4: show stats");
           choice = in.nextInt();



    while (choice !=7){
        if (choice == 1){
            //Read CSV file
            System.out.println("The current list of Contributors: ");
            //function from other class
            readFile.readFile();
            System.out.println("\n");
            E2.selection();
            in.nextLine();
            choice = in.nextInt();

        }
        if (choice == 2){
            // Create stack and input new member into csv file
            System.out.println("Choice 2");
            //function from other class
            E2.userInfo();
            System.out.println("\n");
            E2.selection();
            in.nextLine();
            choice = in.nextInt();

        }
        if (choice == 3){
            System.out.println("choice 3");
            //function from other class
            E2.writeFile();
            System.out.println("\n");
            E2.selection();
            in.nextLine();
            choice = in.nextInt();
        }
        if (choice == 4){
            System.out.println("Choice 4");
            //function from other class
            System.out.println("\n");
            E2.selection();
            in.nextLine();
            choice = in.nextInt();
        }
        if (choice == 5){
            System.out.println("choice 5");
            //function from other class
            System.out.println("\n");
            E2.selection();
            in.nextLine();
            choice = in.nextInt();
        }
        if (choice == 6){
            System.out.println("Choice 6");
            //function from other class
            System.out.println("\n");
            E2.selection();
            in.nextLine();
            choice = in.nextInt();
        }

        // Exit statement for selection 7 
        //System.out.println("W_CS230_Main.java just ran");
        System.out.println("Safely ended application.");
        in.close();
    }


}
}
  //  
public class E2{



// Public Class works Do not change info
public static void readFile(){
    //Read.readFile();
         //choice = in.nextInt();
         //in.nextLine();

           String fileName = "/Users/kilown/Downloads/contributors.csv";
           File file = new File(fileName);


    try {
        Scanner inputStream = new Scanner(file);
        while (inputStream.hasNext()){
            String data = inputStream.next();
            System.out.println(data + "\n");

        }
        inputStream.close();

    } catch (FileNotFoundException ex) {
        Logger.getLogger(readFile.class.getName()).log(Level.SEVERE, null, ex);
    } 
}
   public static void selection(){

    Scanner in = new Scanner (System.in);    
        int choice;



           System.out.println("Welcome User: ");
           System.out.println("Please select your option:");
           System.out.println("1: input new contributor ");
           System.out.println("2: read selected file");
           System.out.println("3: Save File");
           System.out.println("4: Pop");
           System.out.println("5: Exit");
           // System.out.println("4: show stats");
           choice = in.nextInt();
}
public static void writeFile() throws IOException{
    File contList = new File("Contributor.csv");

    FileWriter fileWriter = new FileWriter(contList, true);
    BufferedWriter buffer = new BufferedWriter(fileWriter);
    PrintWriter printWriter = new PrintWriter(buffer);



    if (contList.exists() == false){
        contList.createNewFile();
        System.out.println("file created");
    }else {
        System.out.println("file already exist");
    }
    printWriter.println("scanner information");
    printWriter.close();

}
public static void userInfo(){
    String name = JOptionPane.showInputDialog("Please enter first and last name: ");
    String city = JOptionPane.showInputDialog("Please enter "+name+ " city: ");
    String country = JOptionPane.showInputDialog("Please enter "+name+" country: ");

    System.out.print(name);
    System.out.print(city);
    System.out.print(country);


}
public static void sortStack(){
    public Stack<Integer> sort(Stack<Integer> a) {
        a.sort(new Comparator<Integer>());

        public int compare(Integer contID1, Integer ContID2){
            return contID2.compare(contID1);


        }
    });

return a;
}


}

}