2017-06-22 2 views
0

私はそれがnoobプログラムのビットであることを知っていますが、私は徐々に混乱しています。 'down'関数はcdのように動作し、 'up'関数はcdのように動作します。in-BlueJ Javaファイルマネージャを作成する方法

私はユーザーにファイルやフォルダの作成を許可する手がかりがありません。配列の代わりにarrayListsを使用しようとしましたが、エラーを並べ替えることができませんでした。どんな助けもありがとう。

import java.util.Scanner; 
    class FileManager { 
    //array of arrays will go here 
    String Dir[] = {"UserOne"}; 
    String SystemFolders [] = {"Documents","","",}; 
    String SubFiles [] = {"","","","","",""}; 
    String Nav [][] = { Dir, SystemFolders, SubFiles}; 
    int levelCounter = 0; 
    public void main(String[]args) { 
     Scanner sc = new Scanner (System.in); 
     System.out.println("Enter a command"); 
     String command = sc.next(); 
      if (command.compareTo("down") == 0) 
       down(); 
      //else if is on the way 
    } 
    void down() { 
     //This will execute when the command is 'down' 
     System.out.println(Nav[++levelCounter]); 
    } 
    void up() { 
     //This will execute when the command is 'up'. It acts like cd.. 
     System.out.println(Nav[--levelCounter]); 
    } 
} 

答えて

0

これはあなたのプログラムのエントリポイントは、あなたがあなたの主な方法であなたのFileManagerクラスのメソッドにアクセスするためにそのように

のように、静的なあなたmainメソッドを宣言する必要がある場合メインメソッドでクラスのインスタンスを作成する必要があります。この

public static void main(String[]args) { 
    FileManager fm = new FileManager(); // Creates an instance 
    Scanner sc = new Scanner (System.in); 
    System.out.println("Enter a command"); 
    String command = sc.next(); 
    if (command.equals("down")) // equals will suffice in this case 
           // or equalsIgnoreCase() if you dont want case to be a problem 
     fm.down(); // Notice now this calls the down method from the instance 
    //else if is on the way 
} 

のように続いてcreate folders

create filesまたはこれに例にこれを見て
関連する問題