Results 1 to 4 of 4
  1. #1
    Battlefeldt is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default Compile error in Driver class, help plz

    Hi I've got some problems I can't compile my Driver it keep saying

    "G:\Comp101\Assignments\5\Problem1\Test 1>javac Driver.java
    Driver.java:35: cannot find symbol
    symbol : constructor Thief(int,int,double,double,double)
    location: class Thief
    emil = new Thief(x,y,randomx,randomy,score);"

    Would be realy greatful for any help. My code is below first time I'm using inheritance.


    import java.util.Scanner;

    public class Driver {

    // attributes
    private static Thief emil;
    private static Cop simon;

    public static void main(String [] args) {
    // local variables
    Scanner input = new Scanner(System.in);
    int x, y;
    double randomx, randomy;
    String xy;
    double score = 0;

    // input
    System.out.print("What is the value of x? ");
    x = input.nextInt();
    System.out.print("What is the value of y? ");
    y = input.nextInt();
    emil = new Thief(x,y,randomx,randomy,score);
    System.out.print(emil.shootx());
    }
    }





    public class Position {

    // attributes
    private int x;
    private int y;

    // constructors
    public Position(int xd, int yd) {
    x = xd;
    y = yd;
    }
    }


    public class Shooting extends Position{

    // attributes
    private double randomx;
    private double randomy;
    //String xy;

    // constructors
    public Shooting(int ranx, int rany, int xd, int yd) {
    super(xd, yd);
    randomx = ranx;
    randomy = rany;
    randomx = Math.round(Math.random()*3+0.5);
    randomy = Math.round(Math.random()*3+0.5);
    }
    // method
    public double shootx() {
    System.out.println("\n" + "Random x: ");
    return randomx;
    }
    }




    public class Thief extends Shooting{

    // attributes
    private double randomx;
    private double randomy;
    private double score;


    // constructors
    public Thief(int ranx, int rany, double points, int xd, int yd) {
    super(xd, yd, ranx, rany);
    score = points;
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    The error is telling you exactly what is wrong: you're calling Theif's constructor wrong. Your Thief constructor looks like so:

    Java Code:
    public Thief(int ranx, int rany, double points, int xd, int yd) {
      super(xd, yd, ranx, rany);
      score = points;
    }
    So we can see that it takes as parameters two ints, a double, and two more ints.

    Now let's see how you call it:
    Java Code:
    public class Driver {
    
        // .... code deleted for sake of brevity 
        emil = new Thief(x,y,randomx,randomy,score);
      }
    }
    So you've got the order of things wrong as it should probably be new Thief(x, y, score, randomx, randomy), but also your randomx and randomy are doubles but the constructor is expecting ints. So fix this: either change the constructor to expect doubles or change the randomx and randomy parameters passed to ins.

  3. #3
    senorbum is offline Member
    Join Date
    Aug 2009
    Posts
    76
    Rep Power
    0

    Default

    Did you look at the error message? It is very very clear on what the problem is.

    Also, use the Code tag for posting code. The above is hardly readable

  4. #4
    Battlefeldt is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    Thanks for your help, I new it was something simple but I had been staring myself blind during the last two hours.

    Really appreciate it thank you.

    I'll use the Code command next time I write ;)

    /Simon

Similar Threads

  1. Database Driver Error.....Plz Help!
    By sayan751 in forum NetBeans
    Replies: 0
    Last Post: 02-19-2009, 04:59 PM
  2. compile error
    By angryredantz in forum New To Java
    Replies: 1
    Last Post: 01-23-2009, 10:44 PM
  3. Compile Error - Please Help!!
    By AJ2009 in forum New To Java
    Replies: 10
    Last Post: 01-04-2009, 03:59 PM
  4. Java 1.5 compile time error
    By ank_k in forum New To Java
    Replies: 4
    Last Post: 11-13-2008, 11:12 AM
  5. compile error
    By dirtycash in forum New To Java
    Replies: 6
    Last Post: 12-12-2007, 06:00 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
  •