Chingis Bagdatov
Chingis Bagdatov

Reputation: 11

Writer inside a class does not work in a driver

I have a Java console application which has different views for different users. Inside of each view I have writer and reader, which are used to displaying and getting data. But when I start my driver code it simply doesn't display required data.

public UserView(){
    reader = new BufferedReader(new InputStreamReader(System.in));
    writer = new BufferedWriter(new OutputStreamWriter(System.out));
}

Here is how I initiate my reader and writer inside parent class.

public void main(){
    while(true){
        try{
            writer.write("0. Exit\n");
            writer.write("1. View news\n");
            writer.write("2. View personal info\n");
            writer.write("3. Change password\n");
            writer.write("4. Create user\n");
            String ans = reader.readLine();
            switch(ans){
                case "0":
                    return;
                case "1":
                    viewNews();
                case "2":
                    viewPersonalInfo();
                case "3":
                    changePassword();
                case "4":
                    createUser();
            }
        }
        catch (IOException ioe){
            System.out.println("Wrong");
        }
    }
}

Here is my main method in admin view

public class Main {

    public static UserView view = new AdminView(((Admin)Data.getInstance().getUser("China", "Kaguya")));


    public static void main(String args[]){
        view.main();
    }
}

And here is my driver code. How can I fix this?

Upvotes: 0

Views: 26

Answers (0)

Related Questions