Java 问题 在线等!~急啊...

2025-02-23 16:56:30
推荐回答(3个)
回答1:

OK了:
package com;

public class A2Program {

private static final String STAGE_INFO = "COMPSCI 101 Asst 2 - STAGE 1\n";
public void start() {
System.out.println(STAGE_INFO);

testPlayerWithStrategy(10);
testPlayerWithStrategy(20);
}
// This method tests the getStrategy(), getGameTotal() and
// addToGameTotal() methods of the Player class
private void testPlayerWithStrategy(int strategy) {

Player p = new Player(strategy);

System.out.println("A Player with a strategy of " + strategy);
System.out.println(" " + p.getStrategy());
System.out.println(" " + p.getGameTotal());

p.addToGameTotal(5);
p.addToGameTotal(3);

System.out.println(" " + p.getGameTotal());
}
public static void main(String []args)
{
(new A2Program()).start();
}
}
class Player
{
public int strategy;
public int total;
public Player(int strategy)
{
this.strategy=strategy;
this.total=0;
}
public int getStrategy()
{
return this.strategy;
}
public int getGameTotal()
{
return this.total;
}
public void addToGameTotal(int num)
{
this.total+=num;
}
}

回答2:

public class A2Program {

private static final String STAGE_INFO = "COMPSCI 101 Asst 2 - STAGE 1\n";

public void start() {
System.out.println(STAGE_INFO);

testPlayerWithStrategy(10);
testPlayerWithStrategy(20);
}

private void testPlayerWithStrategy(int strategy) {

Player p = new Player(strategy);

System.out.println("A Player with a strategy of " + strategy);
System.out.println(" " + p.getStrategy());
System.out.println(" " + p.getGameTotal());

p.addToGameTotal(5);
p.addToGameTotal(3);

System.out.println(" " + p.getGameTotal());
}

public static void main(String[] args) {
new A2Program().start();
}
}

回答3:

哥们儿 你能把完整的程序贴出来吗