Related questions
Concept explainers
In Java
Write a complete
use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it
works in conjunction with the two given classes. Use anonymous objects where appropriate.
Deck class details:
Use an ArrayList to store Card objects.
Deck constructor:
The Deck constructor should initialize your ArrayList with the 52 cards found in a standard
deck. Each card is a Card object. Each Card object contains two instance variables ─ num and
suit. Study the Card class definition below for details.
dealCard:
This method removes the highest-indexed card in the ArrayList and returns it. In general, a
method should not do more than what it’s supposed to do. Thus, dealCard should not print
anything.
toString:
This method returns the deck’s contents using the format shown in the output session. In particular,
note that toString should insert a newline after every fifth card. Hint: In coming up with a return
value, use a String local variable. As you generate card values and newlines, concatenate those
items to your local variable using the += operator.
Write your code such that the following classes produce the output shown in the subsequent output.
Output:
13S
12S
1C 2C 3C 4C 5C
6C 7C 8C 9C 10C
11C 12C 13C 1D 2D
3D 4D 5D 6D 7D
8D 9D 10D 11D 12D
13D 1H 2H 3H 4H
5H 6H 7H 8H 9H
10H 11H 12H 13H 1S
2S 3S 4S 5S 6S
7S 8S 9S 10S 11S
/************************************************************* * DeckDriver.java * * This class tests the Deck class. *************************************************************/ public class DeckDriver { public static void main(String[] args) { Deck deck = new Deck(); System.out.println(deck.dealCard()); System.out.println(deck.dealCard()); System.out.println(); System.out.println(deck); } // end main } // end DeckDriver class /**************************************************************** * Card.java * * * This class stores a Card's information. ****************************************************************/ public class Card { private int num; // hold a number between 1 and 13 private char suit; // holds 'C' for clubs, 'D' for diamonds, // 'H' for hearts, 'S' for spades //************************************************** public Card(int num, char suit) { this.num = num; this.suit = suit; } // end Card constructor //************************************************** // Return the card's value in the form of a concatenated // number and character. // For example, 1C = ace of clubs, 12H = queen of hearts. public String toString() { return Integer.toString(num) + suit; } } // end class Card
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- Hello all! Need some help with this assignment. Need to create an array of 8 employees ( see image for details ) Thank you!arrow_forwardQ1: Write the Java code corresponding to the following UML diagram. The class School implements the interface Building. The method computeArea returns the area of the building as width * length. After that, add a testing class with a main method which defines an arrayList that contains three objects. From the main method, print the area of all the three objects. Building> + computeArea() : double + toString() : String School classroomNum: int width: double - length: double + School(classroomNum: int, width: double, length: double) + computeArea() : double + toString() : Stringarrow_forwardJAVA you guys returned the question and said that it is a writing assignment but it is not. It is a java question, multiple-choice no coding. Please help me with this.arrow_forward
- The Delicious class – iterative methods The Delicious class must:• Define a method called setDetails which has the following header: public void setDetails(String name, int price, boolean available) This must find in the ArrayList the Chicken with the given name, change itspricePerKilo to the given price parameter and set whether it is in stock or not. A value of true for the available parameter means the chicken is in stock and a value of false means it is sold out (not in stock). Note that there will only be at most one Chicken object of the given name stored in the ArrayList.• Define a method called removeChicken that takes a single String parameter representing a chicken’s name. This method must remove from the ArrayList the Chicken object (if any) with the given name. The method must return true if a cheese with the given name was found and removed, and false otherwise.The Delicious class – challenge method In the Delicious class complete the findClosestAvailable method: This...arrow_forwardHelparrow_forwardIN JAVA. Any help is appreciated! Thank you! PART 1 : Automobiles Create a data class named Automobile that implements the Comparable interface. Give the class data fields for make, model, year, and price. Then add a constructor, all getters, a toString method that shows all attribute values, and implement Comparable by using the year as the criterion for comparing instances. Write a program named TestAutos that creates an ArrayList of five or six Automobiles. Use a for loop to display the elements in the ArrayList. Sort the Arraylist of autos by year with Collections.sort(). Finally, use a foreach loop to display the ArrayList sorted by year.arrow_forward
- Can you please help me with this, its in java. Thank you. Write classes in an inheritance hierarchy Implement a polymorphic method Create an ArrayList object Use ArrayList methods For this, please design and write a Java program to keep track of various menu items. Your program will store, display and modify salads, sandwiches and frozen yogurts. Present the user with the following menu options: Actions: 1) Add a salad2) Add a sandwich3) Add a frozen yogurt4) Display an item5) Display all items6) Add a topping to an item9) QuitIf the user does not enter one of these options, then display:Sorry, <NUMBER> is not a valid option.Where <NUMBER> is the user's input. All menu items have the following: Name (String) Price (double) Topping (StringBuilder or StringBuffer of comma separated values) In addition to everything that a menu item has, a main dish (salad or sandwich) also has: Side (String) A salad also has: Dressing (String) A sandwich also has: Bread type...arrow_forwardIn Java.arrow_forwardThis is needed in Java Given an existing ArrayList named friendList, find the first index of a friend named Sasha and store it in a new variable named index.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education