{"id":2833,"date":"2023-02-19T21:04:50","date_gmt":"2023-02-19T21:04:50","guid":{"rendered":"https:\/\/www.goodacademic.com\/blog\/questions\/java-programming\/"},"modified":"2023-02-19T21:04:50","modified_gmt":"2023-02-19T21:04:50","slug":"java-programming","status":"publish","type":"questions","link":"https:\/\/www.goodacademic.com\/blog\/questions\/java-programming\/","title":{"rendered":"java programming"},"content":{"rendered":"<div class=\"col-sm-12 messageContent\">\n <b>Learning Goal: <\/b>I&#8217;m working on a java question and need an explanation and answer to help me learn.<\/p>\n<h1>20.6 Program 3: Pokemon cards<\/h1>\n<h2>Objectives<\/h2>\n<ul>\n<li>Using classes, inheritance<\/li>\n<li>Writing getters, setters, and constructors<\/li>\n<li>Overriding <em>toString()<\/em><\/li>\n<\/ul>\n<h2>Description<\/h2>\n<p>Using single inheritance, we have a general class of <em>TradingCard<\/em> which contains string fields for name and image. A two argument constructor initializes the fields and the class has getters (no setters) for both fields. In addition, there is a toString() method that must return the name.<\/p>\n<p>A subclass of <em>TradingCard<\/em> is <em>GamingCard<\/em>. This class has a category and game string fields, which are initialized by the constructor only. GamingCard has getters for both fields, no setter methods for this class. (FYI: another type of Trading Card would be a Sports Card, and more specifically, a Baseball trading card. But we aren&#8217;t going to write code for those.)<\/p>\n<p>Finally, extending this the GamingCard is a PokemonCard which has fields associated with Pokemon cards. All fields have both getters and setters. Those unfamiliar with the Pokemon game can read <a href=\"https:\/\/learn.zybooks.com\/zybook\/SDSUCS160Spring2023\/chapter\/20\/section\/xx\">this<\/a> article. Here are examples of Pokemon characters:<\/p>\n<table>\n<thead>\n<tr>\n<th>Name<\/th>\n<th>Type<\/th>\n<th>Pokedex<\/th>\n<th>Ability<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Charmeleon<\/td>\n<td>Fire<\/td>\n<td>004<\/td>\n<td>Blaze<\/td>\n<\/tr>\n<tr>\n<td>Beedrill<\/td>\n<td>Bug\/Poison<\/td>\n<td>015<\/td>\n<td>Swarm or Sniper<\/td>\n<\/tr>\n<tr>\n<td>Clefairy<\/td>\n<td>Normal<\/td>\n<td>035<\/td>\n<td>Friend Guard<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Hint: The &#8220;super&#8221; keyword is useful in terms of inheritance.<\/p>\n<h2>Instructions<\/h2>\n<p>You will submit four files:<\/p>\n<ol>\n<li>TradingCard.java<\/li>\n<li>GamingCard.java<\/li>\n<li>PokemonCard.java<\/li>\n<li>Program3.java<\/li>\n<\/ol>\n<p>For the class Program3.java just copy and paste the code in the example below to create the class. This is also a good way to test your code by checking to see if your output is the same as the examples.<\/p>\n<h4>Example use in a test program:<\/h4>\n<pre><code>public static void main(String[] args) {TradingCard tc = new TradingCard(\"General\", \"gen.img\");GamingCard gc = new GamingCard(\"Game Name\", \"gc.img\", \"gaming\", \"Pokemon\");PokemonCard charmeleon = new PokemonCard(\"Charmeleon\", \"p004.img\", \"gaming\", \"Pokemon\", \"fire\", 4, \"blaze\");PokemonCard beedrill = new PokemonCard(\"Beedrill\", \"p015.img\", \"gaming\", \"Pokemon\", \"bug\/poison\", 15, \"swarm or sniper\");PokemonCard clefairy = new PokemonCard(\"Clefairy\", \"p035.img\", \"gaming\", \"Pokemon\", \"normal\", 35, \"friend guard\");TradingCard[ ] cards = new TradingCard[5];cards[0] = tc;cards[1] = gc;cards[2] = charmeleon;cards[3] = beedrill;cards[4] = clefairy;for ( TradingCard card : cards )   System.out.println(card);}<\/code><\/pre>\n<p>The output is:<\/p>\n<pre><code>GeneralGame Name: Pokemon characterCharmeleon: Pokemon character, 4, a fire-type with blaze ability.Beedrill: Pokemon character, 15, a bug\/poison-type with swarm or sniper ability.Clefairy: Pokemon character, 35, a normal-type with friend guard ability.<\/code><\/pre>\n<h4>Things to consider:<\/h4>\n<ul>\n<li>Each class should be able to be instantiated.<\/li>\n<li>Each class should have a <code>toString()<\/code> method that overrides its superclass&#8217;s <code>toString()<\/code> method.<\/li>\n<li>None of the classes uses System.out.println. You must use <code>toString()<\/code> to return a string. A test program can print the string that&#8217;s returned from the <code>toString()<\/code> method.<\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learning Goal: I&#8217;m working on a java question and need an explanation and answer to help me learn. 20.6 Program 3: Pokemon cards Objectives Using classes, inheritance Writing getters, setters, and constructors Overriding toString() Description Using single inheritance, we have a general class of TradingCard which contains string fields for name and image. A two [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":[],"disciplines":[654],"paper_types":[],"tagged":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/2833"}],"collection":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions"}],"about":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/types\/questions"}],"author":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/comments?post=2833"}],"version-history":[{"count":0,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/2833\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/media?parent=2833"}],"wp:term":[{"taxonomy":"disciplines","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/disciplines?post=2833"},{"taxonomy":"paper_types","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/paper_types?post=2833"},{"taxonomy":"tagged","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/tagged?post=2833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}