Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Talk about how the current code is structured as it relates to the following OO principles. Each principle should have 2 or 3 specific examples

Talk about how the current code is structured as it relates to the following OO principles. Each principle should have 2 or 3 specific examples from the base code or your intended additional code (i.e. potential for improvement). Encapsulation Delegation Flexibility/Maintainability Here is the code: /* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package project; /** * * @author Admin */ public abstract class Card { //default modifier for child classes /** * Students should implement this method for their specific children classes * * @return a String representation of a card. Could be an UNO card, a regular playing card etc. */ @Override public abstract String toString(); } game.java: /* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package project; import java.util.ArrayList; /** * * @author Admin */ /** * The class that models your game. You should create a more specific child of this class and instantiate the methods * given. * */ public abstract class Game { private final String name;//the title of the game private ArrayList players;// the players of the game public Game(String name) { this.name = name; players = new ArrayList(); } /** * @return the name */ public String getName() { return name; } /** * @return the players of this game */ public ArrayList getPlayers() { return players; } /** * @param players the players of this game */ public void setPlayers(ArrayList players) { this.players = players; } /** * Play the game. This might be one method or many method calls depending on your game. */ public abstract void play(); /** * When the game is over, use this method to declare and display a winning player. */ public abstract void declareWinner(); }//end class GroupOfCards.java: /* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package project; /** * * @author Admin */ import java.util.ArrayList; import java.util.Collections; import java.util.Random; /** * The Deck class consists of 108 Uno cards. There are 4 suits: red, green, blue, yellow * each consisting of one 0 card, two 1s, 2s...8s, 9s cards; two Draw Two cards; two Skip cards; and two Reverse cards. * in addition, there are four Wild cards and four Wild Draw Four cards. */ public class GroupOfCards { private UnoCard[] cards; //tracking how many cards in the deck private int cardsInDeck; public GroupOfCards() { cards = new UnoCard[108]; } //build a deck of 108 cards and assigning specific color and value to each of them public void buildCards(){ //put 4 colors into this array UnoCard.Color[] colors = UnoCard.Color.values(); cardsInDeck = 0; //this forloop used to assign value 0-9 to each color(red, green, blue and yellow for(int i=0; i cardsInDeck){ throw new IllegalArgumentException("can not draw " + n + " there are only "+ cardsInDeck + "cards." ); } UnoCard[] playerGet = new UnoCard[n]; for(int i=0; i < n; i++){ playerGet[i] = cards[--cardsInDeck]; } return playerGet; } } Player.java: /* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package project; /** * * @author Admin */ public class Player { private String playerID; //the unique name for this player /** * @return the player name */ public String getPlayerID() { return playerID; } /** * A method to check that the palyerId length is 3 letters or more * * @param name * @return */ public static boolean checkId(String name) { if (name.length() >= 3) { return true; } return false; } /** * A method that check if the password does not have any special character * * @param pass * @return */ public static boolean checkChar(String name) { for (int i = 0; i < name.length(); i++) { int ch = name.charAt(i); if (!Character.isLetterOrDigit(ch)) { return true; } } return false; } /** * A method to test if the user ii is unique * * @param player1 * @return */ public static boolean checkUnique(String player1, String player2) { if (player1.equals(player2)) { throw new IllegalArgumentException("Error, Enter unique user Id"); } return true; } /** * Ensure that the playerID is unique * * @param givenID the playerID to set */ public void setPlayerID(String givenID) { if (checkId(givenID) && checkChar(givenID)) { this.playerID = givenID; } else { throw new IllegalArgumentException(" Wrong value, try again!"); } } } UnoGame.java: /* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package project; /** * * @author Admin */ public class UnoGame extends Game{ private int currentplayer; public UnoGame(String name) { super(name); } @Override public void play() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void declareWinner() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } } UnoGame.java: /* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package project; /** * * @author Admin */ public class UnoCard extends Card{ private Color color; private Value value; public UnoCard(Color color, Value value){ this.color = color; this.value = value; } enum Color{ Red, Blue, Green, Yellow, Wild; private static final Color[] colors = Color.values(); public static Color getColor(int i){ return Color.colors[i]; } } enum Value{ Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine, DrawTwo, Skip, Reverse, Wild, Wild_Four; private static final Value[] values = Value.values(); public static Value getValue(int i){ return Value.values[i]; } } public Color getColor(){ return this.color; } public Value getValue(){ return this.value; } @Override public String toString(){ return "color of card is: " + this.color +" value of card is: " + this.value; }; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions