Question: First, complete the makeElfArray method. public static Elf[] makeElfArray( String [] a, int [] g ) { Create and return an array of Elves using

 First, complete the makeElfArray method. public static Elf[] makeElfArray( String []

First, complete the makeElfArray method.

public static Elf[] makeElfArray( String [] a, int [] g )

{

Create and return an array of Elves using the parameters. The first elf is created with the first name and int. The second elf is created with the second name and int and so on. The two parameter arrays have the same length.

}

Second, complete the toStringElves method.

public static String toStringElves( Elf[] a )

{

String temp = "";

Loop through the array and call each Elf object's toString method

Add each returned string and " " to temp

You should use an enhanced for loop (1) for practice and (2) because it's cleaner

return temp;

}

Due: Tuesday, January 26, 2021 at 11:59 pm

Complete Program 6.06 The Poorest Elf on codeboard.io. (5 points)

6.06 The Poorest Elf. There is an Elf class that has already been written. In the Main class you will complete three static methods.

First, complete the makeElfArray method.

public static Elf[] makeElfArray( String [] a, int [] g )

{

Create and return an array of Elves using the parameters. The first elf is created with the first name and int. The second elf is created with the second name and int and so on. The two parameter arrays have the same length.

}

Second, complete the toStringElves method.

public static String toStringElves( Elf[] a )

{

String temp = "";

Loop through the array and call each Elf object's toString method

Add each returned string and " " to temp

You should use an enhanced for loop (1) for practice and (2) because it's cleaner

return temp;

}

Third, complete the indexOfPoorest method.

public static String indexOfPoorest( Elf[] a )

{

Return the index of the Elf with the least amount of gold

If there's a tie, return the smallest index

}

If you do the above correctly, the main method should print the following.

JP has 28 pieces of gold.

Keaton has 68 pieces of gold.

David has 83 pieces of gold.

Alexis has 72 pieces of gold.

Karen has 17 pieces of gold.

The poorest elf is Karen who lives at index 4

public class Elf { private String name; private int gold; public Elf(String name, int gold ) { this.name = name; this.gold = gold; } public String getName() { return name; } public int getGold() { return gold; } public String toString() { return name + " has" } 11 + gold + pieces of gold."; // This equals method contains a number of topics that we do not cover in this course // However, this method is needed by the unit tests public boolean equals( Object x) { if ( x instanceof Elf ) { Elf e = (Elf)x; return this.name.equals( e.name ) && this.gold e.gold; ==

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!