question about classes and instance variables

J

jt

Back at the chess thing again... either my brain is dead or there's
something horribly missing in my self-education.

I start off by creating 2 enums

package commonshit;

public enum Color {
BLACK, WHITE
}


public class foo {
String x;
String y;
Integer a;
Integer b;
boolean c;
public foo(String x, String y, Integer a, Integer b, Integer c) {
x = x;
y = y;
a = a;
b = b;
c = true;
}
}

Now lets suppose that I have another class called... oh say bar


public class bar {
private String m;
private foo qr;
private foo qk;
private foo qb;
private foo q;
private foo k;
private foo kb;
private foo kk;
private foo kr;
private foo qrp;
private foo qkp;
private foo qbp;
private foo qp;
private foo kp;
private foo kbp;
private foo kkp;
private foo krp;
public bar(String x) {

this.x = x;
this.qr = new foo(PieceRank.QR, teamColor, startingRow, 0);
this.qk = new ChessPiece(PieceRank.QK, teamColor, startingRow, 1);
this.qb = new ChessPiece(PieceRank.QB, teamColor, startingRow, 2);
this.q = new ChessPiece(PieceRank.Q, teamColor, startingRow, 3);
this.k = new ChessPiece(PieceRank.K, teamColor, startingRow, 4);
this.kb = new ChessPiece(PieceRank.KB, teamColor, startingRow, 5);
this.kk = new ChessPiece(PieceRank.KK, teamColor, startingRow, 6);
this.kr = new ChessPiece(PieceRank.KR, teamColor, startingRow, 7);
this.qrp = new ChessPiece(PieceRank.QRP, teamColor, finishRow, 0);
this.qkp = new ChessPiece(PieceRank.QKP, teamColor, finishRow, 1);
this.qbp = new ChessPiece(PieceRank.QBP, teamColor, finishRow, 2);
this.qp = new ChessPiece(PieceRank.QP, teamColor, finishRow, 3);
this.kp = new ChessPiece(PieceRank.KP, teamColor, finishRow, 4);
this.kbp = new ChessPiece(PieceRank.KBP, teamColor, finishRow, 5);
this.kkp = new ChessPiece(PieceRank.KKP, teamColor, finishRow, 6);
this.krp = new ChessPiece(PieceRank.KRP, teamColor, finishRow, 7);
}
public void displayAPiece(ChessPiece piece)
{
System.out.print(piece.name);
System.out.print(piece.color + " " );
System.out.print(piece.yPos + " " );
System.out.println(piece.alive);
}


}
 
B

Brandon McCombs

jt said:
Back at the chess thing again... either my brain is dead or there's
something horribly missing in my self-education.

I start off by creating 2 enums

package commonshit;

public enum Color {
BLACK, WHITE
}


public class foo {
String x;
String y;
Integer a;
Integer b;
boolean c;
public foo(String x, String y, Integer a, Integer b, Integer c) {
x = x;
y = y;
a = a;
b = b;
c = true;
}
}

Now lets suppose that I have another class called... oh say bar


public class bar {
private String m;
private foo qr;

You don't have to put all your foo instances on separate lines.

public bar(String x) {

this.x = x;
this.qr = new foo(PieceRank.QR, teamColor, startingRow, 0);
this.qk = new ChessPiece(PieceRank.QK, teamColor, startingRow, 1);
this.qb = new ChessPiece(PieceRank.QB, teamColor, startingRow, 2);
this.q = new ChessPiece(PieceRank.Q, teamColor, startingRow, 3);
this.k = new ChessPiece(PieceRank.K, teamColor, startingRow, 4);
this.kb = new ChessPiece(PieceRank.KB, teamColor, startingRow, 5);
this.kk = new ChessPiece(PieceRank.KK, teamColor, startingRow, 6);
this.kr = new ChessPiece(PieceRank.KR, teamColor, startingRow, 7);
this.qrp = new ChessPiece(PieceRank.QRP, teamColor, finishRow, 0);
this.qkp = new ChessPiece(PieceRank.QKP, teamColor, finishRow, 1);
this.qbp = new ChessPiece(PieceRank.QBP, teamColor, finishRow, 2);
this.qp = new ChessPiece(PieceRank.QP, teamColor, finishRow, 3);
this.kp = new ChessPiece(PieceRank.KP, teamColor, finishRow, 4);
this.kbp = new ChessPiece(PieceRank.KBP, teamColor, finishRow, 5);
this.kkp = new ChessPiece(PieceRank.KKP, teamColor, finishRow, 6);
this.krp = new ChessPiece(PieceRank.KRP, teamColor, finishRow, 7);
}
public void displayAPiece(ChessPiece piece)
{
System.out.print(piece.name);
System.out.print(piece.color + " " );
System.out.print(piece.yPos + " " );
System.out.println(piece.alive);
}


}



So what is your question?
 
J

jt

Brandon McCombs wrote:

There is no question. I pressed the send button before I was done
typing and when I cancelled my message it seems to have stayed visible
for some (not to me). I was able to resolve my own problem...I tried to
kill the thread but it must have stayed on at least one news server,
although not on the one I use.

Sorry for bugging you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top