Write a java program consisting of following classes.
A class number stores nine cards number from 2 to 10 using nine_no() method and face cards are stored using instance variable.A method code() determine the card from the suit with number and the color of the card.There is another method called face() to find the face card from suit with color.
The main() method is written in the classed NumDemo. Create an object of playing cards with suit name and number or suit name and face card.
source file name: NumDemo.java
class facecard
{
int cdno;
String col;
public facecard()
{
cdno=1;
}
}
class Numbers extends facecard
{
int[] cardnums={2,3,4,5,6,7,8,9,10};
facecard fcob=new facecard();
public void nine_no()
{
for(int i=0;i<cardnums.length;i++)
System.out.println("card no:"+cardnums[i]);
}
public void face(int fc,String col)
{
fcob.cdno=fc;
fcob.col=col;
System.out.println("card no:"+fcob.cdno+"color name:"+fcob.col);
}
public void code(facecard fc,String col)
{
System.out.println("card no:"+fc.cdno+"color name:"+col);
}
}
class NumDemo
{
public static void main(String as[])
{
System.out.println("Card Program");
Numbers nos=new Numbers();
nos.nine_no();
nos.face(11,"red");
nos.face(12,"green");
facecard ob=new facecard();
nos.code(ob,"blue");
}
}
0 Comments
Post a Comment