I'm kind of new to java and have trouble manipulating arrays, but especially arrays of objects.
I'm taking a new XML class and I have not learned the advanced Java concepts yet.
here is the problem that I am having
The file below contains the main method.
import java.io.FileWriter;
import java.io.IOException;
public class SistersTest
{
public static void main (String[] args)
throws IOException
{
FileWriter fw;
SisterCities sc;
sc = buildSisterCities ();
fw = new FileWriter ("output-01.xml");
fw.write (toXML (sc));
fw.close ();
}
public static String toXML (SisterCities sc)
{
// throw new RuntimeException ("Not implemented yet.");
}
public static SisterCities buildSisterCities ()
{
City chicago = new City ("Chicago", "USA");
City accra = new City ("Accra", "Ghana");
City amman = new City ("Amman", "Jordan");
City athens = new City ("Athens", "Greece");
City belgrade = new City ("Belgrade", "Serbia and Montenegro");
City losAngeles = new City("Los Angeles", "USA");
City [] chicagoSisters = {accra, amman, athens, belgrade};
City [] athensSisters = {chicago, losAngeles};
SisterCities sc = new SisterCities ();
chicago.setSisters(chicago
Sisters);
sc.addCity(chicago);
athens.setSisters(athensSi
sters);
sc.addCity(athens);
return sc;
}
}
I need help building the methods in the two skeleton classes (see below) so that they will work with the implementation given above.
P.S
Please put in comments so that that I will understand how this works (or not).
here are the 2 classes that I need to develope.
(1)
public class City
{
public City (String name, String country)
{
//throw new RuntimeException ("Not implemented yet.");
}
public City (String name, String country, City [] sisters)
{
//throw new RuntimeException ("Not implemented yet.");
}
public void setSisters (City [] sisters)
{
// throw new RuntimeException ("Not implemented yet.");
}
public String getName ()
{
// throw new RuntimeException ("Not implemented yet.");
}
public String getCountry ()
{
// throw new RuntimeException ("Not implemented yet.");
}
public City [] getSisters ()
{
// throw new RuntimeException ("Not implemented yet.");
}
}
(2)
package hw01;
public class SisterCities
{
public SisterCities ()
{
throw new RuntimeException ("Not implemented yet.");
}
public void addCity (City city)
{
throw new RuntimeException ("Not implemented yet.");
}
public int getNumCities ()
{
// throw new RuntimeException ("Not implemented yet.");
}
public City getCity (int i)
{
// throw new RuntimeException ("Not implemented yet.");
}
}
Start Free Trial