我正在尝试自己学习 Java,但我正在做一个问题。我正在创建一个程序,该程序从用户那里获取输入以制作两个 Team 对象,然后计算获胜者。每个团队都有一个名称和位置,表示为 String 对象,以及表示为双值的进攻和防御能力,使用luck() 方法在 0 和 1 之间随机初始化。
import java.util.Scanner;
public class Team {
public String name;
public String location;
public double offense;
public double defense;
public String awayName;
public String awayLocation;
public double awayOffense;
public double awayDefense;
/**
* Create a team with specified name and location, and with offense and defense capabilities
* randomly initialized using the luck() method.
*/
public Team(String name, String location) {
this.name = name;
this.location = location;
}
/**
* The luck() method returns a random value between 0 and 1, using Math.random().
*
* @returns a real value in range [0,1]
*/
public double luck() {
return Math.random();
}
/**
* Run a competition against the specified visiting team
*
* @param other the team to play against
* @returns the winner team
*/
Team play(Team visitor) {
home = (this.offense + this.defense + 0.2) * this.luck();
away = (visitor.offense + visitor.defense) * visitor.luck();
return winner;
}
/**
* Run a competition between two teams specified on standard input.
* Print statistics of the winner.
* <p>
* Each team is read in the following format :
* <pre>
* <name>
* <location>
* </pre>
*/
public static void main(String[] args) {
System.out.println("Enter name and location for home team (on separate lines)");
Scanner tn = new Scanner(System.in);
Team team = new Team("Name","Location");
team.name = tn.nextLine();
Scanner tl = new Scanner(System.in);
team.location = tl.nextLine();
Team home = new Team(team.name, team.location);
System.out.println("Enter name and location for away team (on separate lines)");
Scanner atn = new Scanner(System.in);
team.awayName = atn.nextLine();
Scanner atl = new Scanner(System.in);
team.awayLocation = atl.nextLine();
Team away = new Team(team.awayName, team.awayLocation);
System.out.println("Home team is: " + team.name+ " from " + team.location + " rated <home_team_offense> (offense) + <home_team_defense> (defense)");
System.out.println("Away team is: " + team.awayName+ " from " + team.awayLocation + " rated <home_team_offense> (offense) + <home_team_defense> (defense)");
// Create a home and an away team object with the given data.
// Call the home team's play() method with the away team as visitor parameter.
// Print out the winner.
评论部分告诉我我需要做什么,尽管我不确定从这里去哪里。我被卡住了,认为到目前为止我所做的甚至可能都不正确,有人可以推动我朝着正确的方向前进吗?请帮忙!谢谢!