Question: 1. Open the starter code program and explore the Kingdom and Fiefdom classes and the Main.java. 2. Create the following methods: getName() - returns the
1. Open the starter code program and explore the Kingdom and Fiefdom classes and the Main.java.
2. Create the following methods:
getName() - returns the name of the Kingdom
getPop() - returns the population of the Kingdom
getNumLords() - returns the number of lords in the Fiefdom
3. Attempt the following code in the main:
Fiefdom c9 = new Fiefdom(Test,1,1);
Fiefdom c10 = new Kingdom(Test,1,1);
Fiefdom c11 = new Kingdom(Test,1);
If any of the above lines cause an error comment them out.
4. Write the code that will output the name of the Kingdom with the largest population.
5. Write the code that will create a new ArrayList of only the Fiefdom objects. You must use a loop. Output the new ArrayList using a loop to verify that all elements in the list have a numLords.
Hint: Java has a keyword called instanceof that will return true if an object is an instance of a particular class. This might be useful to use for this task. Example:
if(a instanceof SomeObject)
{ //do something }
The conditional will return true if A is a SomeObject or a subclass of SomeObject



1 Main.java import java.util.ArrayList; 2 3 public class Main 4 { 5 public static void main(String[] args) 6 { 7 Kingdom c1 = new Fiefdom("Colombo", 648034, 3); 8 Kingdom c2 = new Kingdom("Moratuwa", 185031); 9 Kingdom c3 = new Kingdom("Kandana", 33424); 10 Kingdom C4 = new Kingdom("Pettyagoda", 30717); 11 Kingdom c5 = new Fiefdom("Devinuwara", 45000, 1); 12 Kingdom c6 = new Kingdom ("Jaffna", 169102); 13 Kingdom c7 = new Fiefdom("Negomb", 137223, 2); 14 Kingdom c8 = new Kingdom("kerunegala", 28571); 15 16 Kingdom[] dataLands = {c1, c2, C3, C4, C5, C6, 7, c8}; 17 ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
