Question: TISIC your leuciler , Complete the Creature class. Main.java Creature.java: ublic class Creature { private String name; private int power; All creatures have a name


TISIC your leuciler , Complete the Creature class. Main.java Creature.java: ublic class Creature { private String name; private int power; All creatures have a name and a power level which starts at 10. public Creature( Strings ) { name = S; power = 10; } The split method returns a new Creature that has the same name as the Creature who calls the split method except the last letter has been dropped. And its power is two less than the original. The absorb method has a Creature parameter. The Creature who calls the absorb method gets half of the parameter's power and the parameter Creature loses half their power. (5 points) public Creature split() { /* if name.length() 0, the new Creature has an empty string as its name */ } public void absorb( Creature c) { } public String getName() { return name; } public int getPower() { return power; } public class Main { public static void main(String[] args) { Creature c1 = new Creature( "Noah" ); System.out.println( c1.getPower() ); // 10 Creature c2 = c1.split(); System.out.println( c2.getName() ); // "Noa" System.out.println( c2.getPower() ); // 8 Creature c3 = c2.split(); System.out.println( c3.getName()); // "No" System.out.println( c3.getPower() ); // 6 Creature c4 = new Creature( "Victim" ); c1.absorb( c4 ); System.out.println( c1.getPower() ); // 15 System.out.println( 04.getPower); // 5 } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
