Reputation: 57
I am in an entry level Java class and we have been assigned a Team Competition project. I have completed it for the most part but when I compile it I get a few errors stating:
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
Source code
/**
* 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);
}
}
I have checked the class discussion board and even looked up how to fix this, but nothing has been able to help me out! Thanks ahead of time!
Upvotes: 0
Views: 609
Reputation: 4017
Your constructor is defined as
public Team(String n, String loc, int o, int d)
Notice that the constructor takes two arguments of type String and two arguments as type int.
You should use the following code in the main method.
System.out.println("Team 1: Enter an Offensive Rating (0-100).");
int o1 = scanner.nextInt();
System.out.println("Team 1: Enter a Defensive Rating (0-100).");
int o2 = scanner.nextInt();
Always use THIS as a reference.
Upvotes: 0
Reputation: 178263
You have a constructor taking 2 strings and 2 ints, but you attempt to pass 4 strings. Convert the last two strings to int
before passing them to the constructor.
For competition
, it's misspelled when declared. Change
public static int competion(Team home, Team away){
to
public static int competition(Team home, Team away){
Upvotes: 2