我正在学习入门级 Java 课程,我们被分配了一个团队竞赛项目。我已经完成了大部分,但是当我编译它时,我得到了一些错误说明:
3 errors found:
File: C:\Users\Brett\Documents\DrJava\Team.java [line: 70]
Error: The constructor Team(java.lang.String, java.lang.String, java.lang.String, java.lang.String) is undefined
File: C:\Users\Brett\Documents\DrJava\Team.java [line: 79]
Error: The constructor Team(java.lang.String, java.lang.String, java.lang.String, java.lang.String) is undefined
File: C:\Users\Brett\Documents\DrJava\Team.java [line: 80]
Error: The method competition(Team, Team) is undefined for the type Team
源代码
/**
* Project 1 -- Team Competition Simulator
*
* This program gets input from the user to make two Team objects and then
* calculates the winner.
*
* @Brett Donahue
* @lmf
* @16 September 2013
*/
import java.lang.Math.*;
import java.util.Scanner;
public class Team{
final int offense, defense;
final double luck;
final String name, location;
/**
* Class constructor
*
* @param n = name of the team to be created
* @param loc = location of the team to be created
* @param o = offensive rating of the team to be created
* range should be 0-100
* @param d = defensive rating of the team to be created
* range should be 0-100
* luck is to be randomly generated using java.lang.Math
* range: 0-1
*/
public Team(String n, String loc, int o, int d){
offense = o;
defense = d;
name = n;
location = loc;
luck = (double)(Math.random() * (1 - 0) + 0);
}
/**
* Perform the calculation explained on the project description
* Print out the ratings of each Team
* Print out the winning Team's location and name
* You do not have to worry about there being a draw
*/
public static int competion(Team home, Team away){
System.out.println(home.name + ": Offense " + home.offense + "Defense "+home.defense);
System.out.println(away.name + ": Offense " + away.offense + "Defense "+home.defense);
double ovr1 = (1/25.0)*(home.offense+home.defense+(0.2*(home.offense+home.defense))*home.luck) + 0.4;
double ovr2 = (1/25.0)*(away.offense+away.defense+(0.2*(away.offense+away.defense))*away.luck) + 0.4;
if(ovr1 > ovr2)
System.out.println("The "+home.name+" of "+home.location+" have won!");
else if(ovr1 < ovr2)
System.out.println("The "+away.name+" of "+away.location+" have won!");
return 0;
}
/**
* Prompt user for input
* Formatting = prompt "Name Location Offense Defense"
* Make two Team objects
* Compete
*/
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Team 1: Enter a Name.");
String n1 = scanner.nextLine();
System.out.println("Team 1: Enter a Location.");
String l1 = scanner.nextLine();
System.out.println("Team 1: Enter an Offensive Rating (0-100).");
String o1 = scanner.nextLine();
System.out.println("Team 1: Enter a Defensive Rating (0-100).");
String d1 = scanner.nextLine();
Team team1 = new Team(n1,l1,o1,d1);
System.out.println("Team 2: Enter a Name.");
String n2 = scanner.nextLine();
System.out.println("Team 2: Enter a Location.");
String l2 = scanner.nextLine();
System.out.println("Team 2: Enter an Offensive Rating (0-100).");
String o2 = scanner.nextLine();
System.out.println("Team 2: Enter a Defensive Rating (0-100).");
String d2 = scanner.nextLine();
Team team2 = new Team(n2,l2,o2,d2);
competition(team1,team2);
}
}
我检查了课堂讨论板,甚至查找了如何解决这个问题,但没有任何东西可以帮助我!提前谢谢!