0
안녕하세요, 저는 planeManagerApp을 만들고 있습니다. 나는 항공, HashMap (String, Plane)을 포함하는 TreeMap을 가지고있다;PlaneManagerApp - 항공사에서 덮어 쓰기
항공사가 속한 비행기를 인쇄하고 싶습니다. 그래서 RyanAir에게는 3 대의 비행기가 그들을 위해 인쇄하고 AerLingus는 3 대의 비행기가 그들을 위해 인쇄하기를 원합니다. 그러나 나는 비행기를 추가 할 때 마지막으로 항공사를 추가하게됩니다.
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
public class MainApp
{
public static void main(String[] args)
{
//PlaneStore map = new PlaneStore();
Airline a1 = new Airline("Aer Lingus");
Plane p1 = new Plane("A01", 150.5, 10.5, 500, Plane.AIRPLANETYPE.AIRBUS);
Plane p2 = new Plane("B01", 50.3, 1.5, 91, Plane.AIRPLANETYPE.CORPORATE);
Plane p3 = new Plane("C01", 12.2, -3.1, 56, Plane.AIRPLANETYPE.AIRBUS);
Airline a2 = new Airline("Brian Air");
Plane p4 = new Plane("D01", 10.5, 1.5, 430, Plane.AIRPLANETYPE.PRIVATE);
Plane p5 = new Plane("E01", 0.3, 2.1, 101, Plane.AIRPLANETYPE.CORPORATE);
Plane p6 = new Plane("F01", 2.2, -3, 291, Plane.AIRPLANETYPE.AIRBUS);
HashMap<String, Plane> airlineMap = new HashMap<String, Plane>();
airlineMap.put(p1.getFlightNumber(), p1);
airlineMap.put(p2.getFlightNumber(), p2);
airlineMap.put(p3.getFlightNumber(), p3);
airlineMap.put(p4.getFlightNumber(), p4);
airlineMap.put(p5.getFlightNumber(), p5);
airlineMap.put(p6.getFlightNumber(), p6);
TreeMap<Airline, HashMap<String, Plane>> map = new TreeMap<Airline, HashMap<String, Plane>>();
map.put(a1, airlineMap);
map.put(a2, airlineMap);
System.out.println("\n-------- PRINT KEY DETAILS --------");
for(Map.Entry theEntry : map.entrySet())
System.out.println(theEntry.getKey());
for(Map.Entry theEntry : map.entrySet())
{
HashMap<String, Plane> map2= (HashMap<String, Plane>)theEntry.getValue();
System.out.println("\n-------- PRINT CLIENT DETAILS --------");
for(Map.Entry theNextEntry : map2.entrySet())
System.out.println(theNextEntry.getValue());
}
//Plane p4 = new Plane("D01", 300.9, 45, 402, Plane.AIRPLANETYPE.PRIVATE);
//Plane p5 = new Plane("E01", 455, 23, 100, Plane.AIRPLANETYPE.AIRBUS);
//Airline.airlineMap.add("Aer Lingus", p1);
// map.put(Airline.getAirlineName(), p1);
}
}
어떻게 연관시킬 수 있습니까? – Pendo826
그건 디자인, 스타일 및 선호도의 문제입니다. 한 가지 방법은 평면 (p1, p2, p3, ...)을 키로, 항공사 (a1, a2)를 값으로 사용하여 다른 hashMap을 만드는 것입니다. 이 새로운 해시 맵을 반복 할 때 원하는 결과를 얻어야합니다. – Scott