java programming

Learning Goal: I’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 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.

A subclass of TradingCard is GamingCard. 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’t going to write code for those.)

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 this article. Here are examples of Pokemon characters:

Name Type Pokedex Ability
Charmeleon Fire 004 Blaze
Beedrill Bug/Poison 015 Swarm or Sniper
Clefairy Normal 035 Friend Guard

Hint: The “super” keyword is useful in terms of inheritance.

Instructions

You will submit four files:

  1. TradingCard.java
  2. GamingCard.java
  3. PokemonCard.java
  4. Program3.java

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.

Example use in a test program:

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);}

The output is:

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.

Things to consider:

  • Each class should be able to be instantiated.
  • Each class should have a toString() method that overrides its superclass’s toString() method.
  • None of the classes uses System.out.println. You must use toString() to return a string. A test program can print the string that’s returned from the toString() method.

Are you struggling with your paper? Let us handle it - WE ARE EXPERTS!

Whatever paper you need - we will help you write it

Get started

Starts at $9 /page

How our paper writing service works

It's very simple!

  • Fill out the order form

    Complete the order form by providing as much information as possible, and then click the submit button.

  • Choose writer

    Select your preferred writer for the project, or let us assign the best writer for you.

  • Add funds

    Allocate funds to your wallet. You can release these funds to the writer incrementally, after each section is completed and meets your expected quality.

  • Ready

    Download the finished work. Review the paper and request free edits if needed. Optionally, rate the writer and leave a review.