1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alenkasestr [34]
2 years ago
10

Specific Instructions

Computers and Technology
1 answer:
Goryan [66]2 years ago
6 0

In the most common use of the term, a class can be seen as a blueprint used to create objects. In other words, object(s) are created from a class in Java.

<h3>Creating a Class</h3><h3>Code:</h3>

import java.util.*;

class Card{

 private String suit;

 private int value;

 public Card(String s,int v){

   suit = s;

   value = v;

 }

 public String getSuit(){

   return suit;

 }

 public int getValue(){

   return value;

 }

 public void display(){

   System.out.println(value+"("+suit+")");

 }

}

class Deck{

 private ArrayList<Card> deck;

 private ArrayList<Card> drawn;

 public Deck(){

   deck = new ArrayList<Card>();

   drawn = new ArrayList<Card>();

   String[] arr = {"Club","Spade","Heart","Diamond"};

   for(String s : arr){

     for(int i=1;i<=13;i++){

       deck.add(new Card(s,i));

     }

   }

 }

 public void draw(){

   drawn.add(deck.get(0));

   deck.remove(0);

 }

 public void draw(int N){

   if(N > deck.size()){

     N = deck.size();

   }

   for(int i=0;i<N;i++){

     draw();

   }

 }

 public void showDrawn(){

   for(Card c : drawn){

     c.display();

   }

 }

 public void shuffle(){

   Collections.shuffle(deck);

 }

 public void restore(){

   restore(drawn.size());

 }

 public void restore(int N){

   if(N > drawn.size()){

     N = drawn.size();

   }

   for(int i=0;i<N;i++){

     deck.add(drawn.get(0));

     drawn.remove(0);

   }

 }

 public void showDeck(){

   for(Card c : deck){

     c.display();

   }

 }

}

class Test{

 public static void main(String[] args){

   Deck d = new Deck();

   System.out.println("Original deck\n");

   d.showDeck();

   d.draw(8);

   System.out.println("\nDeck after drawing 8 cards\n");

   d.showDeck();

   d.shuffle();

   System.out.println("\nDeck after shuffling\n");

   d.showDeck();

   d.restore();

   System.out.println("\nDeck after restoring cards\n");

   d.showDeck();

 }

}

<h3>Test Output:</h3>

C:\Users\hp\Desktop>java Test

Original deck

1(Club)

2(Club)

3(Club)

4(Club)

5(Club)

6(Club)

7(Club)

8(Club)

9(Club)

10(Club)

11(Club)

12(Club)

13(Club)

1(Spade)

2(Spade)

3(Spade)

4(Spade)

5(Spade)

6(Spade)

7(Spade)

8(Spade)

9(Spade)

10(Spade)

11(Spade)

12(Spade)

13(Spade)

1(Heart)

2(Heart)

3(Heart)

4(Heart)

5(Heart)

6(Heart)

7(Heart)

8(Heart)

9(Heart)

10(Heart)

11(Heart)

12(Heart)

13(Heart)

1(Diamond)

2(Diamond)

3(Diamond)

4(Diamond)

5(Diamond)

6(Diamond)

7(Diamond)

8(Diamond)

9(Diamond)

10(Diamond)

11(Diamond)

12(Diamond)

13(Diamond)

<h3>Draw action:</h3>

9(Club)

10(Club)

11(Club)

12(Club)

13(Club)

1(Spade)

2(Spade)

3(Spade)

4(Spade)

5(Spade)

6(Spade)

7(Spade)

8(Spade)

9(Spade)

10(Spade)

11(Spade)

12(Spade)

13(Spade)

1(Heart)

2(Heart)

3(Heart)

4(Heart)

5(Heart)

6(Heart)

7(Heart)

8(Heart)

9(Heart)

10(Heart)

11(Heart)

12(Heart)

13(Heart)

1(Diamond)

2(Diamond)

3(Diamond)

4(Diamond)

5(Diamond)

6(Diamond)

7(Diamond)

8(Diamond)

9(Diamond)

10(Diamond)

11(Diamond)

12(Diamond)

13(Diamond)

<h3 /><h3>Shuffling action:</h3>

12(Diamond)

8(Spade)

4(Spade)

6(Diamond)

10(Spade)

13(Club)

7(Heart)

13(Heart)

7(Diamond)

9(Heart)

11(Diamond)

5(Heart)

8(Diamond)

9(Diamond)

3(Spade)

13(Spade)

4(Heart)

2(Heart)

3(Heart)

5(Diamond)

11(Heart)

11(Club)

10(Club)

9(Club)

3(Diamond)

4(Diamond)

6(Spade)

9(Spade)

10(Heart)

11(Spade)

5(Spade)

12(Spade)

1(Spade)

6(Heart)

12(Heart)

13(Diamond)

1(Heart)

2(Diamond)

1(Diamond)

7(Spade)

12(Club)

10(Diamond)

2(Spade)

8(Heart)

  • Restore action

12(Diamond)

8(Spade)

4(Spade)

6(Diamond)

10(Spade)

13(Club)

7(Heart)

13(Heart)

7(Diamond)

9(Heart)

11(Diamond)

5(Heart)

8(Diamond)

9(Diamond)

3(Spade)

13(Spade)

4(Heart)

2(Heart)

3(Heart)

5(Diamond)

11(Heart)

11(Club)

10(Club)

9(Club)

3(Diamond)

4(Diamond)

6(Spade)

9(Spade)

10(Heart)

11(Spade)

5(Spade)

12(Spade)

1(Spade)

6(Heart)

12(Heart)

13(Diamond)

1(Heart)

2(Diamond)

1(Diamond)

7(Spade)

12(Club)

10(Diamond)

2(Spade)

8(Heart)

1(Club)

2(Club)

3(Club)

4(Club)

5(Club)

6(Club)

7(Club)

8(Club)

You can learn more about creating a class here brainly.com/question/10410845

You might be interested in
anyone got a class named computer literacy? or sum similar to using Microsoft programs? i need a lotttt of help, im 3 units behi
seropon [69]

Answer:

I use google docs

Explanation:

I am in 6th grade but i am in expert in computers.

6 0
3 years ago
Read 2 more answers
In poor weather , you should ___ your following distance.
svlad2 [7]

Answer:

lengthen

Explanation:

will take more time to stop on wet and slippery surfaces

3 0
3 years ago
Ivy is a student. She is looking for some freelance assignments during her vacation. Which of the following networking sites can
lara [203]

The answer is D. XING


3 0
3 years ago
A Python function cannot under normal circumstances reference a module variable for its value.
marishachu [46]
This is false because
6 0
3 years ago
Read 2 more answers
What is a symbol such as a heavy dot or another character that precedes a text in a power point
Fantom [35]

Answer:

<em>I </em><em>think </em><em>the </em><em>answer </em><em>is </em><em>a </em><em>bullet.</em>

<em>Hope </em><em>this </em><em>helps</em>

4 0
1 year ago
Other questions:
  • Show what this program prints. Be exact and complete. Can you explain the behavior of each print statement? 1 2 3 4 5 6 7 public
    12·1 answer
  • PLEASE HELP ASAP!!!!
    14·1 answer
  • Which address correctly represents one that is composed of two halves, one assigned to a network adapter manufacturer, and the o
    6·1 answer
  • Name three actions you can perform on an inserted image.
    7·2 answers
  • For each of these statements find a domain for which the statement is true and a domain for which the statement is false. a) Eve
    13·1 answer
  • Hai<br> ill give 100 point if some won answers dis
    14·2 answers
  • a term to describe article that can be displayed in their entirety as opposed to abstract and reference only?​
    10·1 answer
  • What is the code i need to do
    12·1 answer
  • Where is the element coded in a web page.
    13·1 answer
  • A user has become compromised as a result of visiting a specific web page, without clicking on any kind of content. What type of
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!