1.Below is the code for SingletonEcercise.java file 2.i have  attached a picture for instructions  3. kindly include comments when editing the file so that i can have a better understanding . import java.util.*; enum Suit { SPADES, HEARTS, CLUBS, DIAMONDS } class Card { public Card(Suit s, int n) { suit = s; if((n < 2) || (n > 14)) { throw new IllegalArgumentException( ); } number = n; } public void print( ) { switch(number) { case 11: System.out.print("Jack"); break; case 12: System.out.print("Queen"); break; case 13: System.out.print("King"); break; case 14: System.out.print("Ace"); break; default: System.out.print(number); break; } System.out.print(" of "); switch(suit) { case SPADES: System.out.println("spades."); break; case HEARTS: System.out.println("hearts."); break; case CLUBS: System.out.println("clubs."); break; case DIAMONDS: System.out.println("diamonds."); break; } } private Suit suit; private int number; } class Deck { public Deck( ) { cards = new ArrayList( ); // build the deck Suit[] suits = {Suit.SPADES, Suit.HEARTS, Suit.CLUBS, Suit.DIAMONDS}; for(Suit suit: suits) { for(int i = 2; i <= 14; i++) { cards.add(new Card(suit, i)); } } // shuffle it! Collections.shuffle(cards, new Random( )); } public void print( ) { for(Card card: cards) { card.print( ); } } private List cards; } public class SingletonExercise { public static void main(String args[]) { Deck deck = new Deck( ); deck.print( ); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

1.Below is the code for SingletonEcercise.java file

2.i have  attached a picture for instructions 

3. kindly include comments when editing the file so that i can have a better understanding .

import java.util.*;

enum Suit {
SPADES,
HEARTS,
CLUBS,
DIAMONDS
}

class Card {
public Card(Suit s, int n) {
suit = s;
if((n < 2) || (n > 14)) {
throw new IllegalArgumentException( );
}
number = n;
}

public void print( ) {
switch(number) {
case 11:
System.out.print("Jack");
break;
case 12:
System.out.print("Queen");
break;
case 13:
System.out.print("King");
break;
case 14:
System.out.print("Ace");
break;
default:
System.out.print(number);
break;
}
System.out.print(" of ");
switch(suit) {
case SPADES:
System.out.println("spades.");
break;
case HEARTS:
System.out.println("hearts.");
break;
case CLUBS:
System.out.println("clubs.");
break;
case DIAMONDS:
System.out.println("diamonds.");
break;
}
}

private Suit suit;
private int number;
}


class Deck {
public Deck( ) {
cards = new ArrayList<Card>( );

// build the deck
Suit[] suits = {Suit.SPADES, Suit.HEARTS, Suit.CLUBS, Suit.DIAMONDS};
for(Suit suit: suits) {
for(int i = 2; i <= 14; i++) {
cards.add(new Card(suit, i));
}
}

// shuffle it!
Collections.shuffle(cards, new Random( ));
}

public void print( ) {
for(Card card: cards) {
card.print( );
}
}

private List<Card> cards;
}


public class SingletonExercise {
public static void main(String args[]) {
Deck deck = new Deck( );
deck.print( );
}
}

 

Compulsory Task 1
Follow these steps:
●
Download the Singleton Exercise.java file.
Change the Deck class into a Singleton class.
Change the main method to get the Deck instance rather than creating a
new object.
The program should print all 52 cards in random order.
Transcribed Image Text:Compulsory Task 1 Follow these steps: ● Download the Singleton Exercise.java file. Change the Deck class into a Singleton class. Change the main method to get the Deck instance rather than creating a new object. The program should print all 52 cards in random order.
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education