Last active
December 4, 2016 07:13
-
-
Save JoeUnsung/88e92eab5d40a5057f421b2da89b50be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package joe; | |
import java.lang.*; | |
import java.util.*; | |
class Connection { | |
private String departure; | |
private String arrival; | |
Connection(String city1, String city2){ | |
this.departure = city1; | |
this.arrival = city2; | |
} | |
public String returnAri(){ | |
return arrival; | |
} | |
public String returnDep(){ | |
return departure; | |
} | |
} | |
public class P9_20101062_1 { | |
public static void main(String[] args) { | |
String temp = " "; | |
Connection[] con = new Connection[14]; | |
con[0] = new Connection("SanJose", "SanFrancisco"); | |
con[1] = new Connection("SanJose", "Anchorage"); | |
con[2] = new Connection("NewYork", "Anchorage"); | |
con[3] = new Connection("NewYork", "SanJose"); | |
con[4] = new Connection("NewYork", "SanFrancisco"); | |
con[5] = new Connection("NewYork", "Honolulu"); | |
con[6] = new Connection("Anchorage", "NewYork"); | |
con[7] = new Connection("Anchorage", "SanJose"); | |
con[8] = new Connection("Honolulu", "NewYork"); | |
con[9] = new Connection("Honolulu", "SanFrancisco"); | |
con[10] = new Connection("Denver", "SanJose"); | |
con[11] = new Connection("SanFrancisco", "NewYork"); | |
con[12] = new Connection("SanFrancisco", "Honolulu"); | |
con[13] = new Connection("SanFrancisco", "Denver"); | |
// (1) 배열 con의 정보를 차례대로 ArrayList에 저장할 것 | |
ArrayList<String> ariv = new ArrayList<String>(); | |
ArrayList<String> depa = new ArrayList<String>(); | |
for (int i = 0 ; i < con.length ; i++){ | |
ariv.add(con[i].returnAri()); | |
depa.add(con[i].returnDep()); | |
} | |
// (2) ArrayList 결과를 출력할 것 (Flight Information 출력 부분) | |
System.out.println("------------------------------------------"); | |
System.out.println("Welcome to Flight Tour NORANG Balloon ! !"); | |
System.out.println("------------------------------------------"); | |
System.out.println(); | |
System.out.println("<<< Flight Information >>>"); | |
for(int i = 0 ; i < ariv.size() ; i++){ | |
System.out.println( depa.get(i) + "->" + ariv.get(i)); | |
} | |
// (3) 출발 도시를 중복없이 한번씩만 LinkedList에 저장하고 출력할 것 | |
//(Cities in the DB 출력 부분) // 링크드리스트는 두개. | |
System.out.println("------------------------------------------"); | |
System.out.println("<<< Cities in the DB >>>"); | |
System.out.println("------------------------------------------"); | |
//LINKED LIST | |
LinkedList<String> l_db = new LinkedList<String>(); | |
LinkedList<String> l_final_route = new LinkedList<String>(); | |
// LINKED LIST안에 중복되지 않도록 DEPA에 있는 원소들을 넣어줌. | |
temp = depa.get(0); | |
l_db.add(depa.get(0)); | |
for (int i =0 ; i < ariv.size() ; i++){ | |
if (!temp.equals(depa.get(i))){ | |
l_db.add(depa.get(i)); | |
temp = depa.get(i); | |
} | |
} | |
for (int i = 0 ; i < l_db.size() ; i++ ){ | |
System.out.println(l_db.get(i)); | |
} | |
System.out.println("------------------------------------------"); | |
// (4) 경로를 물어 나가면서 도시들을 LinkedList에 저장해 나갈 것. 즉, 최종 route가 LinkedList에 저장되어 나가야 한다. | |
Scanner s = new Scanner(System.in); | |
String temp2, start_point; | |
while(true){ | |
System.out.println(" "); | |
System.out.println("Let's plan a round-trip route!"); | |
System.out.print("Enter the starting city :"); | |
temp2 = s.nextLine(); | |
if (temp2.equals(l_db.get(0)) || temp2.equals(l_db.get(1)) || temp2.equals(l_db.get(2)) || temp2.equals(l_db.get(3)) || temp2.equals(l_db.get(4)) || temp2.equals(l_db.get(5))){ | |
System.out.println("From "+temp2+" you can fly directly to : "); | |
System.out.println(" "); | |
for(int i = 0 ; i < ariv.size() ; i++){ | |
if ( temp2.equals(depa.get(i))){ | |
System.out.println(ariv.get(i)); | |
} | |
} | |
System.out.println(" "); | |
System.out.println("------------------------------------------"); | |
break; | |
} | |
else{ | |
System.out.println("***** You can't get to that city by a direct flight. ***** "); | |
} | |
} | |
start_point = temp2; | |
while(true){ | |
System.out.println(" "); | |
System.out.print("Where do you want to go from " + temp2 + "?" ); | |
temp2 = s.nextLine(); | |
if (temp2.equals(l_db.get(0)) || temp2.equals(l_db.get(1)) || temp2.equals(l_db.get(2)) || temp2.equals(l_db.get(3)) || temp2.equals(l_db.get(4)) || temp2.equals(l_db.get(5))){ | |
l_final_route.add(temp2); | |
System.out.println("From "+temp2+" you can fly directly to : "); | |
System.out.println(" "); | |
for(int i = 0 ; i < ariv.size() ; i++){ | |
if ( temp2.equals(depa.get(i))){ | |
System.out.println(ariv.get(i)); | |
} | |
} | |
System.out.println(" "); | |
System.out.println("------------------------------------------"); | |
} | |
else{ | |
System.out.println("***** You can't get to that city by a direct flight. ***** "); | |
} | |
if(temp2.equals(start_point)){ | |
break; | |
} | |
} | |
System.out.println("===================================="); | |
System.out.println("<<< Your Final Route >>>"); | |
System.out.println(" "); | |
System.out.print(start_point); | |
for(int i = 0 ; i < l_final_route.size(); i++){ | |
System.out.print(" -> " + l_final_route.get(i)); | |
} | |
System.out.println(" "); | |
System.out.println("------------------------------------"); | |
System.out.println(" "); | |
System.out.println(" Have a nice Trip with NORANG Balloon ~ "); | |
// (5) 최종 route를 출력할 것 | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment