java 找不到构造函数,Java-找不到符号构造函数

I'm completely new to Java, so I'm sorry if my question is dumb. Im working on this assignment, and I've been reading about main methods for hours now, but I just cant figure it out. I put some of my code below. I might be way off here, but what I'm hoping to accomplish is to get the main method to start the constructor, but when I compile I get an error saying "cannot find symbol - constructor Player". Now, Im guessing this has something to do with the string parameters of the constructor, but I'm all out. If anyone could shed some light on this, probably very simple problem, I'd be very happy :)

public class Player {

private String nick;

private String type;

private int health;

public static void main(String[] args)

{

Player player = new Player();

player.print();

}

public Player(String nickName, String playerType)

{

nick = nickName;

type = playerType;

health = 100;

System.out.println("Welcome " + nick +" the " + type + ". I hope you are ready for an adventure!");

}

public void print()

{

System.out.println("Name: " + nick);

System.out.println("Class: " + type);

System.out.println("Remanining Health: " + health);

}

解决方案

Player has no no-arg constructor, you could use:

Player player = new Player("My Nickname", "Player Type");

If you wish to prompt the user for the Player arguments, you can read like so:

Scanner scanner = new Scanner(System.in);

System.out.print("Enter Player Name:");

String nickName = scanner.nextLine();

System.out.print("Enter Player Type:");

String playerType = scanner.nextLine();

Player player = new Player(nickName, playerType);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值