Java 所选内容不包含主类型错误
所以基本上我被赋予了一项任务,向一个类添加5个方法。我已经提供了4个类,其中我们只编辑1。我试图运行该程序,但我不断收到一个错误,说选择不包含主类型。我正在尝试执行totalPack方法 这是包含我的方法的类Java 所选内容不包含主类型错误,java,class,methods,main,Java,Class,Methods,Main,所以基本上我被赋予了一项任务,向一个类添加5个方法。我已经提供了4个类,其中我们只编辑1。我试图运行该程序,但我不断收到一个错误,说选择不包含主类型。我正在尝试执行totalPack方法 这是包含我的方法的类 import java.util.ArrayList; public class PackCards { private ArrayList<Card> pack; /* * Create a random pack of size n
import java.util.ArrayList;
public class PackCards {
private ArrayList<Card> pack;
/*
* Create a random pack of size n
*/
public PackCards(int n) {
Card c;
pack = new ArrayList<>();
for (int i = 1; i <= n; i++) {
c = new Card();
pack.add(c);
}
}
public void printPack() {
for (Card c : pack) {
System.out.println(c.cardString());
}
}
/*
* Total the numerical value of all the cards in the pack
*/
public int totalPack() {
int total = 0;
for(int i = 0; i < PackCards.length; i++) {
total = total + PackCards[i];
}
}
你能分享更多信息吗?基本上,这个项目模拟了一组扑克牌,我必须添加一些方法,这些方法可以对扑克牌执行不同的操作,例如返回所有加起来的扑克牌的值。我必须编辑的类是packCards.java类。这个类包含我的所有方法。java类是包含main方法的类。当我执行packCards.java类时,我得到的选择不包含main类型错误。这就是你收到这条信息的原因。如果您想使PackCards.java成为可执行文件,您应该在其中包含main方法,或者从驱动程序类运行pack cards的方法。另外,如果希望在不使用main方法的情况下运行,可以使用static或sysme.exit。那么我是否应该将main方法从driver.java复制到packCards.java?您应该只执行driver.class。我只能假设player.testTotal调用PackCards totalPack并打印结果。你没有展示这门课,所以我不能肯定。但是,不能从命令行直接运行PackCards,因为它不包含main方法。
public class Driver {
public static void main(String[] args) {
// Edit number to control size of pack
PlayCards player = new PlayCards(10);
player.testTotal(); // Remove comments to test each method
// Edit string for a different suit
// player.testSuit("Hearts");
// player.testLargest();
// player.testDuplicate();
}
}