Question: Java with NetBeans Exercise 13-4 Work with an enumeration and documentation In this exercise, youll create an enumeration. Then, youll retrofit some existing code to

Java with NetBeans

Exercise 13-4 Work with an enumeration and documentation

In this exercise, youll create an enumeration. Then, youll retrofit some existing code to use the enumeration.

Review the code

1. Open the project named ch13_ex4_CardSuitTester in the extra_ex_starts folder.

2. Review the code. Note that the Main class creates a Card object and sets its suit to 0 and its number to 1.

3. Run the application. It should display a message that says, Ace of spades!.

4. In the Main class, modify the code so it sets the suit to 5.

5. Run the application again. Since there is no suit that corresponds to 5, the application should display a message that says, Ace of ????!.

Create an enumeration and use it

6. In the murach.card package, create an enumeration named Suit. This enumeration should specify four suits: spades, hearts, diamonds, and clubs.

7. In the Card class, modify the code so it uses the Suit enumeration as the type for the suit instance variable.

8. In the Main class, modify the displayCard method so it uses the Suit enumeration to check the suit of the card.

9. In the Main class, experiment by modifying the code that sets the suit and number for the Cart object. Note that you cant set an illegal suit, but you can set an illegal number.

10. Run the application to make sure it works correctly.

Add javadoc comments and generate documentation

11. In the Card class, add javadoc comments. Make sure these comments include @param and @return tags wherever those tags are appropriate.

12. Generate the documentation for the project.

13. View the documentation for the Card class. This documentation should include descriptions for all of the constructors and methods as well as information about all parameters and return values.

14. View the documentation for the Suit enumeration. Note that this documentation includes a method named values returns an array of the constants that are in the Suit enumeration.

Listed below are the 2 classes

package murach.ui;

import murach.card.Card;

public class Main {

public static void main(String[] args) { System.out.println("Welcome to the Suit Tester "); Card card = new Card(); card.setSuit(0); card.setNumber(1);

displayCard(card); } public static void displayCard(Card card) { if (card.getNumber() == 1) { System.out.print("Ace"); } else if (card.getNumber() == 11) { System.out.print("Jack"); } else if (card.getNumber() == 12) { System.out.print("Queen"); } else if (card.getNumber() == 13) { System.out.print("King"); } else if (card.getNumber() > 13) { System.out.print("????"); } else { System.out.print(card.getNumber()); } System.out.print(" of "); if (card.getSuit() == 0) { System.out.print("spades"); } else if (card.getSuit() == 1) { System.out.print("hearts"); } else if (card.getSuit() == 2) { System.out.print("clubs"); } else if (card.getSuit() == 3) { System.out.print("diamonds"); } else { System.out.print("????"); } System.out.println("!"); } }

package murach.card;

public class Card { private int suit; private int number; public void setSuit(int suit) { this.suit = suit; } public int getSuit() { return this.suit; } public void setNumber(int number) { this.number = number; } public int getNumber() { return this.number; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!