我正在尝试使我的名为ZawTennisPlayer的程序使用构造函数和显示方法输出以下内容。 我正在使用一个名为TestTennisPlayer2的示例代码来对其进行测试并获得所需的输出。 我当前的代码是:
xticks([1 2 3]);
xticklabels({'string 1','string 2','string 3'});
但是,当该程序编译时,却出现错误“该类没有接受String []的静态void main方法”。当我运行它时。我知道我应该在ZawTennisPlayer程序中的某个位置添加一些“公共静态void main(String [] args)”,但是我不确定在哪里。任何想法我如何可以修复程序以获得所需的输出?预先感谢!
我用来测试程序的示例代码“ TestTennisPlayer2”是:
public class ZawTennisPlayer
{
//instance variables
private String playerName;
private String country;
private int rank;
private int age;
private int wins;
private int losses;
//default constructor
public ZawTennisPlayer()
{
playerName=null;
country=null;
rank=0;
age=0;
wins=0;
losses=0;
}
//parameterized constructor
public ZawTennisPlayer(String playerName,String country)
{
this.playerName=playerName;
this.country=country;
rank=0;
age=0;
wins=0;
losses=0;
}
//parameterized constructor
public ZawTennisPlayer(String playerName,String country,int rank, int age)
{
this.playerName=playerName;
this.country=country;
this.rank=rank;
this.age=age;
wins=0;
losses=0;
}
//parameterized constructor
public ZawTennisPlayer(String playerName,String country,int rank, int age,int wins,int losses)
{
this.playerName=playerName;
this.country=country;
this.rank=rank;
this.age=age;
this.wins=wins;
this.losses=losses;
}
//all accesor and mutator method for all six fields.
public String getPlayerName()
{
return playerName;
}
public void setPlayerName(String playerName)
{
this.playerName = playerName;
}
public String getCountry()
{
return country;
}
public void setCountry(String country)
{
this.country = country;
}
public int getRank()
{
return rank;
}
public void setRank(int rank)
{
this.rank = rank;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public int getWins()
{
return wins;
}
public void setWins(int wins)
{
this.wins = wins;
}
public int getLosses()
{
return losses;
}
public void setLosses(int losses)
{
this.losses = losses;
}
//method to display player details
public void displayPlayer()
{
System.out.println("Player's name: " + getPlayerName());
System.out.println("Player's country: " + getCountry());
System.out.println("Player's rank: " + getRank());
System.out.println("Player's age: " + getAge());
System.out.println("Player's wins: " + getWins());
System.out.println("Player's losses: " + getLosses());
System.out.println();
}
}
答案 0 :(得分:2)
如评论中所述,似乎您正在尝试运行ZawTennisPlayer
的地方TestTennisPlayer2
如果通过命令提示符运行,请使用
>javac TestTennisPlayer2.java
>java TestTennisPlayer2
或通过Eclipse IDE
open TestTennisPlayer2.java, right click -> run as > java application