Question #58997

Question: Create the following class to represent a cartoon character in an application.

CartoonCharacter
- name
- catchPhrase
+ CartoonCharacter()
+ getName() : String
+ setName(String):void
+ getCatchPhrase(): String
+ setCatchPhrase(String): void
+ sayCatchPhrase(): void

Create another class CartoonApp.java to instantiate each of the following characters..

Character name: Catch phase:
Bart Simpson Eat my shorts!
Yogi Bear I’m smarter that the average bear!
Buzz Lightyear To infinity and beyond!
Tweety Pie I tought I taw a puddy tat!

For each of the character objects set the appropriate instance variables, e.g. for the Bart character set the name to Bart Simpson and the catchPhase to Eat my shorts. For each character object in turn call the sayCatchPhrase method which should output to screen <name> says <catchPhrase>

Expert's answer

package com.company;
public class CartoonCharacter {
private String Name;
private String catchPhrase;
/**
Constructs a cartoon character object
*/
public CartoonCharacter() {}
/**
Returns the name of the character
@return Name of the character
*/
public String GetName() {
return Name;
}
/**
Returns the catch phrase of the character
@return catchPhrase of the character
*/
public String getCatchPhrase() {
return catchPhrase;
}
/**
Sets the name to the parameter value
@param newName the name of the character
*/
public void setName(String newName) {
Name = newName;
}
/**
Sets the catch phrase to the parameter value
@param newcatchPhrase the catch phrase of the character
*/
public void setCatchPhrase(String newcatchPhrase) {
catchPhrase = newcatchPhrase;
}
public void sayCatchPhrase() {
System.out.println(this.Name + " says " + this.catchPhrase);
}
}
}
package com.company;
public class CartoonApp {
public static void main(String[] args) {
CartoonCharacter oneCharacter = new CartoonCharacter();
oneCharacter.setName("Bart Simpson");
oneCharacter.setCatchPhrase("Eat my shorts!");
oneCharacter.sayCatchPhrase();
}
CartoonCharacter twoCharacter = new CartoonCharacter();
twoCharacter.setName("Yogi Bear");
twoCharacter.setCatchPhrase("I'm smarter that the average bear!");
twoCharacter.sayCatchPhrase();
CartoonCharacter threeCharacter = new CartoonCharacter();
threeCharacter.setName("Buzz Lightyear");
threeCharacter.setCatchPhrase("To infinity and beyond!");
threeCharacter.sayCatchPhrase();
CartoonCharacter fourCharacter = new CartoonCharacter();
fourCharacter.setName("Tweety Pie");
fourCharacter.setCatchPhrase("I tought I saw a puddy tat!");
fourCharacter.sayCatchPhrase();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS