私は入門レベルの 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);
}
}
クラスのディスカッション ボードを確認し、これを修正する方法を調べましたが、何も解決できませんでした。お早めにどうぞ!