简单的Java代码给我一个编译器退出错误

时间:2019-05-31 17:30:28

标签: java

因此,我试图编写一些简单的Java代码,该代码使用地图来验证用户的登录信息。如果用户名和密码匹配,则显示“欢迎使用”,否则显示“访问被拒绝”。现在,我不断收到错误消息,指出“编译器退出状态1”。有人可以向我解释这意味着什么以及如何解决吗?我对编码非常陌生,因此花了一些时间才能理解错误以及如何修复错误。谢谢:)

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class User{
  String self, userMap;
    self.user = userMap;

  public static void main(String[] args) {
    Scanner name = new Scanner(System.in);
      System.out.println("Login: ");
        name = scanner.nextLine();

    Scanner password = new Scanner();
    System.out.println("Password: ");
      password = scanner.nextLine();

  Map<String, Login> credentials = new HashMap<>();

    credentials.put("Bob", new Login("Bob", "psw1", "user"));
    credentials.put("Jim", new Login("Jim", "psw2", "user"));
    credentials.put("Liz", new Login("Liz", "psw3", "super user"));

  Scanner scanner = new Scanner(System.in);
  String name, password;

  if (credentials.containsKey(name) && 
  credentials.get(name).getPassword().equals(password)) {

    System.out.println("Welcome " + name + "!");

  } else {

    System.out.println("Access Denied!");
    }
  }
}

0 个答案:

没有答案