In: Computer Science
Here is the code,
Card.java
public class Card {
private int number;
public Card(int number){
this.number = number;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
@Override
public String toString() {
return "Card{" +
"number=" + number +
'}';
}
}
CardPlay.java
import java.util.*;
public class CardPlay {
// I have assumed card with values that is : (1-10), Jack - 11, Queen - 12, Kind - 13, Ace - 14;
private List<Card> cards;
public CardPlay(){
cards = new ArrayList<>();;
}
private void hand(Card[] mCards){
cards.addAll(Arrays.asList(mCards));
}
private boolean issorted(){
for(int i=1; i<cards.size(); i++){
if(cards.get(i).getNumber() < cards.get(i-1).getNumber()) return false;
}
return true;
}
public static void main(String[] args) {
Card[] mCards = new Card[14];
mCards[0] = new Card(12);
mCards[1] = new Card(1);
mCards[2] = new Card(9);
mCards[3] = new Card(8);
mCards[4] = new Card(2);
mCards[5] = new Card(14);
mCards[6] = new Card(5);
mCards[7] = new Card(7);
mCards[8] = new Card(13);
mCards[9] = new Card(3);
mCards[10] = new Card(6);
mCards[11] = new Card(4);
mCards[12] = new Card(10);
mCards[13] = new Card(11);
CardPlay cardPlay = new CardPlay();
cardPlay.hand(mCards);
System.out.println("isSorted? : "+cardPlay.issorted());
}
}
If you have any doubts, then put in the comments. Also do upvote the solution.