-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathDemo6.java
More file actions
65 lines (55 loc) · 1.7 KB
/
Demo6.java
File metadata and controls
65 lines (55 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.ArrayList;
class Continent{
String cName;
ArrayList <Countries> listOfCountries = new ArrayList<Countries>();
double size;
Continent( String cName, String[] conName){
this.cName=cName;
for (int i=0; i<conName.length; i++){
listOfCountries.add( new Countries (conName [i]));
}
}
public void displayCountries(){
for (int i=0; i<listOfCountries.size(); i++){
System.out.println(listOfCountries.get(i).conName);
}
}
} // Continent class end here
class Countries{
String conName;
ArrayList <City> listOfCities = new ArrayList<City>();
City capitalCity = new City();
Countries(String conName, String[] cityName){
this.conName=conName;
for (int i=0; i<cityName.length; i++){
listOfCities.add(new City(cityName[i]));
}
}
public void displayCities(){
for (int i=0; i<listOfCities.size(); i++){
System.out.println(listOfCities.get(i).cityName);
}
}
public int noOfCities(){
return listOfCities.size();
}
public String capital(){ return capitalCity.capital;}
class City{
String cityName;
long population;
Countries cun;
protected String capital;
public void displayCity(){
System.out.println("City name is : " + cityName);
}
}
}
public class Demo6{
public static void main(String args[]){
String [] conName={"Pakistan", "Korea"};
String [] cityName={"Karachi","Solo"};
// Continent asia = new Continent("western asia", conName);
Countries c1 = new Countries("Pakistan", cityName);
c1.displayCities();
}
}