Results 1 to 3 of 3
  1. #1
    RoKr93 is offline Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0

    Default Problem compiling- simple code

    I'm taking an intro to Java class right now and working on my first project. I have a semester of experience with C++, so everything's been pretty straightforward, but occasionally I hit a snag with constructors or classes, since that's not something I've ever had to deal with.

    My current issue is that my project won't compile, and it appears to be an error with my constructor. The error message I get from my IDE is in line 71 and reads "cannot find symbol symbol: constructor." However, as far as I can tell everything looks in order. What am I missing?

    Here's my code:
    Java Code:
    /**
      * Project 1 -- Team Competition Simulator 
      * 
      * This program gets input from the user to make two Team objects and then
      * calculates the winner.
      * 
      * @author
      * @lab section number and lab instructor's name
      * @date date of completion
      */
     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);
       }
     }
    Any assistance would be appreciated. Thanks!

  2. #2
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    265
    Rep Power
    2

    Default Re: Problem compiling- simple code

    your Team constructor accepts 2 strings and 2 ints, and you pass as arguments 4 strings

  3. #3
    RoKr93 is offline Member
    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0

    Default Re: Problem compiling- simple code

    Oh rats. Should have known it'd be something dumb like that. Thank you!

Similar Threads

  1. Replies: 1
    Last Post: 05-03-2012, 09:31 AM
  2. Plz give me the code of following simple problem..
    By juhiswt in forum New To Java
    Replies: 3
    Last Post: 03-07-2011, 03:54 AM
  3. Problem with simple code in Java ME SDK 3.0
    By marvas in forum CLDC and MIDP
    Replies: 0
    Last Post: 10-13-2010, 06:58 PM
  4. simple code not compiling
    By cliffh in forum New To Java
    Replies: 8
    Last Post: 09-30-2010, 05:47 AM
  5. Simple "if" statement problem....compiling error.
    By CYANiDE in forum New To Java
    Replies: 4
    Last Post: 10-14-2009, 09:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •