• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling multiple source files.

 
Chidimma Juliana
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have been trying to compile two source files from a command line using the examples on K & B SCJP study guide. Am using Window Vista and my compiler(JDK) is working properly.

Please, could someone explain to me how to compile these two programs from a command line;

class GameShape{
public void displayshape(){
System.out.println("displaying shape");
}
}

class PlayerPiece extends Gameshape{
public void movePiece(){
System.out.println("moving game piece");

AND

public class TestShapes{
public static void main(String[] args){
PlayerPiece player = new PlayerPiece();
TilePiece title = new TilePiece();
doshapes(player);
doshapes(tile);
}
public static void doshapes(GameShape shape){
shape.displayShape();
}

}

}
}

class TilePiece extends GameShape{
public void getAdjacent(){
System.out.println("getting adjacent tiles");
}
}

Your response is highly needed
Thank you.
 
Ogeh Ikem
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch

Try this:

 
Chidimma Juliana
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I have compiled some other class and it was successful.

But in this situation, I have two programs saved in two different files,

GameShape.java file contains:
class GameShape{
public void displayShape(){
System.out.println("displaying shape");
}
}

class PlayerPiece extends GameShape{
public void movePiece(){
System.out.println("moving game piece");

}
}

class TilePiece extends GameShape{
public void getAdjacent(){
System.out.println("getting adjacent tiles");
}
}


AND

TestShapes.java files contains:

public class TestShapes{
public static void main(String[] args){
PlayerPiece player = new PlayerPiece();
TilePiece title = new TilePiece();
doShapes(player);
doShapes(title);
}
public static void doShapes(GameShape shape){
shape.displayShape();
}

}

Error messages from the compiler;

C:\Users\Chidimma>cd C:\Documents and Settings\Chidimma\Desktop\Allfiles

C:\Documents and Settings\Chidimma\Desktop\Allfiles>javac TestShapes.java
.\GameShape.java:7: cannot find symbol
symbol: class Gameshape
class PlayerPiece extends Gameshape{
^
TestShapes.java:7: doshapes(GameShape) in TestShapes cannot be applied to (Playe
rPiece)
doshapes(player);
^
TestShapes.java:8: cannot find symbol
symbol : variable tile
location: class TestShapes
doshapes(tile);
^
TestShapes.java:11: cannot find symbol
symbol : method displayShape()
location: class GameShape
shape.displayShape();
^
4 errors

C:\Documents and Settings\Chidimma\Desktop\Allfiles>

Thank you.

 
Ogeh Ikem
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Chidimma. Please use the code button to paste your code.
 
Ogeh Ikem
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have spelling errors in your classes. For example

PlayerPiece extends Gameshape

should be

PlayerPiece extends GameShape

Also, in the TestShapes class

doshapes(tile);

should be

doshapes(title);
 
Chidimma Juliana
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ogeh,

Thank you so much. After correcting the errors, the program compiled and executed.

 
Ogeh Ikem
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic