Uyibiza njani indlela evela kwelinye iklasi?

Ibhlog

Uyibiza njani indlela evela kwelinye iklasi?

Ke ndiyindoda e-OOP kwaye ngoku ndinengxaki yokusebenzisa umsebenzi kwenye indlela. Iklasi engezantsi iklasi ephambili yomdlalo wekhadi. Apha yenza indawo yamakhadi ngokwenza into evela kwiklasi yoMdlalo. Iqala umdlalo ngomgangatho owenziweyo kwaye kufuneka uprinte ubungakanani bedesika.



Game game; System.out.println('Welcome!'); play = true; while (play) { game = new Game(3); //Create deck of card based on number of ranks given game.play(); //Starts the game with deck of card }

}

ukutyibilika kwewindows algorithm python

Iklasi engezantsi yiklasi yoMdlalo. Xa umdlalo uqala kufuneka uprinte ubungakanani bomgangatho owenziwe.



public class Run { 

public static void main(String[] args) {

|_+_|

Udidi olungezantsi ludidi lweDikki apho lwenza khona umgangatho kwaye unendlela ebuyisa ubungakanani belo deck.



public class Game {  
public Game(int ranks)
{
Deck Main = new Deck(ranks);
}
public static void play()
{
System.out.println(Main.size()); //Where the error occurs
}

Iklasi yokugqibela yiklasi yeklasi.

public class Deck { 

private ArrayList cards;

public Deck(int range) {
cards = new ArrayList();
for (int i=1; i<=range; i++)
{
Card card = new Card(1, i);
Card card2 = new Card(2, i);
Card card3 = new Card(3, i);
Card card4 = new Card(4, i);
cards.add(card);
cards.add(card2);
cards.add(card3);
cards.add(card4);
}
}
public int size()
{
int num=cards.size();
return num;
}

Kuya kuba yimpazamo ecacileyo ngenxa yokusilela kwam ukuqonda ukuze umntu abonise into amakayenze ukuyilungisa?

#Java #eop

phendula imifanekiso yendalo