SlideShare a Scribd company logo
1 of 11
Download to read offline
import java.util.*;
import acm.program.*;
public class FlightPlanner extends ConsoleProgram {
/* Private instance variables */
private FlightDB flights; //creates a new database
private ArrayList enteredCities = new ArrayList(); //keeps track of entered cities
private String firstCity; //keeps track of the first city entered by the user
public void init() {
//passes the text file to the database to read and parse
flights = new FlightDB("flights.txt");
}
public void run() {
welcome();
askForFistCity();
askForMoreCities();
printFinalRoute();
}
/* Welcomes the user */
private void welcome() {
println("Welcome to Flight Planner");
println("Here is a list of all the cities in our database");
Iterator it = flights.getCities();
while(it.hasNext()) {
println(" " + it.next());
}
println("Let's plan a round-trip route!");
}
/* asks the user for the starting city and prints out
* all the possible destination cities for that city */
private void askForFistCity() {
while(true) {
firstCity = readLine("Enter the starting city: ");
if(flights.ContainsKey(firstCity)) {
enteredCities.add(firstCity);
break;
}
else{
println("You can't get to that city by a direct flight.");
println("Here is a list of all the cities in our database");
Iterator it = flights.getCities();
while(it.hasNext()) {
println(" " + it.next());
}
}
}
println("From " + firstCity + " you can fly directly to:");
Iterator it = flights.findRoute(firstCity);
while(it.hasNext()) {
println(" " + it.next());
}
}
/* asks the user for the cities he/she wants to fly to,
* and prints out possible destination cities for each city
* until the user enters the starting city */
private void askForMoreCities() {
String city = firstCity;
String lastCity = city;
while(true) {
city = readLine("Where do you want to go from " + city + "? ");
if(city.equals(firstCity)) {
break;
}
if(flights.ContainsKey(city) == true) {
lastCity = city;
enteredCities.add(city);
}
else{
city = lastCity;
println("You can't get to that city by a direct flight.");
}
println("From " + city + " you can fly directly to:");
Iterator it = flights.findRoute(city);
while(it.hasNext()) {
println(" " + it.next());
}
}
}
/* prints out the chosen route */
private void printFinalRoute() {
println("The route you've chosen is");
String route = enteredCities.get(0);
for(int i = 1; i " + enteredCities.get(i);
}
route += " -> " + enteredCities.get(0);
println(route);
}
}
import acm.program.*;
public class FlightPlanner extends ConsoleProgram {
/* Private instance variables */
private FlightDB flights; //creates a new database
private ArrayList enteredCities = new ArrayList(); //keeps track of entered cities
private String firstCity; //keeps track of the first city entered by the user
public void init() {
//passes the text file to the database to read and parse
flights = new FlightDB("flights.txt");
}
public void run() {
welcome();
askForFistCity();
askForMoreCities();
printFinalRoute();
}
/* Welcomes the user */
private void welcome() {
println("Welcome to Flight Planner");
println("Here is a list of all the cities in our database");
Iterator it = flights.getCities();
while(it.hasNext()) {
println(" " + it.next());
}
println("Let's plan a round-trip route!");
}
/* asks the user for the starting city and prints out
* all the possible destination cities for that city */
private void askForFistCity() {
while(true) {
firstCity = readLine("Enter the starting city: ");
if(flights.ContainsKey(firstCity)) {
enteredCities.add(firstCity);
break;
}
else{
println("You can't get to that city by a direct flight.");
println("Here is a list of all the cities in our
database");
Iterator it = flights.getCities();
while(it.hasNext()) {
println(" " + it.next());
}
}
}
println("From " + firstCity + " you can fly directly to:");
Iterator it = flights.findRoute(firstCity);
while(it.hasNext()) {
println(" " + it.next());
}
}
/* asks the user for the cities he/she wants to fly to,
* and prints out possible destination cities for each city
* until the user enters the starting city */
private void askForMoreCities() {
String city = firstCity;
String lastCity = city;
while(true) {
city = readLine("Where do you want to go from " + city + "?
");
if(city.equals(firstCity)) {
break;
}
if(flights.ContainsKey(city) == true) {
lastCity = city;
enteredCities.add(city);
}
else{
city = lastCity;
println("You can't get to that city by a direct flight.");
}
println("From " + city + " you can fly directly to:");
Iterator it = flights.findRoute(city);
while(it.hasNext()) {
println(" " + it.next());
}
}
}
/* prints out the chosen route */
private void printFinalRoute() {
println("The route you've chosen is");
String route = enteredCities.get(0);
for(int i = 1; i " + enteredCities.get(i);
}
route += " -> " + enteredCities.get(0);
println(route);
}
}
Solution
import java.util.*;
import acm.program.*;
public class FlightPlanner extends ConsoleProgram {
/* Private instance variables */
private FlightDB flights; //creates a new database
private ArrayList enteredCities = new ArrayList(); //keeps track of entered cities
private String firstCity; //keeps track of the first city entered by the user
public void init() {
//passes the text file to the database to read and parse
flights = new FlightDB("flights.txt");
}
public void run() {
welcome();
askForFistCity();
askForMoreCities();
printFinalRoute();
}
/* Welcomes the user */
private void welcome() {
println("Welcome to Flight Planner");
println("Here is a list of all the cities in our database");
Iterator it = flights.getCities();
while(it.hasNext()) {
println(" " + it.next());
}
println("Let's plan a round-trip route!");
}
/* asks the user for the starting city and prints out
* all the possible destination cities for that city */
private void askForFistCity() {
while(true) {
firstCity = readLine("Enter the starting city: ");
if(flights.ContainsKey(firstCity)) {
enteredCities.add(firstCity);
break;
}
else{
println("You can't get to that city by a direct flight.");
println("Here is a list of all the cities in our database");
Iterator it = flights.getCities();
while(it.hasNext()) {
println(" " + it.next());
}
}
}
println("From " + firstCity + " you can fly directly to:");
Iterator it = flights.findRoute(firstCity);
while(it.hasNext()) {
println(" " + it.next());
}
}
/* asks the user for the cities he/she wants to fly to,
* and prints out possible destination cities for each city
* until the user enters the starting city */
private void askForMoreCities() {
String city = firstCity;
String lastCity = city;
while(true) {
city = readLine("Where do you want to go from " + city + "? ");
if(city.equals(firstCity)) {
break;
}
if(flights.ContainsKey(city) == true) {
lastCity = city;
enteredCities.add(city);
}
else{
city = lastCity;
println("You can't get to that city by a direct flight.");
}
println("From " + city + " you can fly directly to:");
Iterator it = flights.findRoute(city);
while(it.hasNext()) {
println(" " + it.next());
}
}
}
/* prints out the chosen route */
private void printFinalRoute() {
println("The route you've chosen is");
String route = enteredCities.get(0);
for(int i = 1; i " + enteredCities.get(i);
}
route += " -> " + enteredCities.get(0);
println(route);
}
}
import acm.program.*;
public class FlightPlanner extends ConsoleProgram {
/* Private instance variables */
private FlightDB flights; //creates a new database
private ArrayList enteredCities = new ArrayList(); //keeps track of entered cities
private String firstCity; //keeps track of the first city entered by the user
public void init() {
//passes the text file to the database to read and parse
flights = new FlightDB("flights.txt");
}
public void run() {
welcome();
askForFistCity();
askForMoreCities();
printFinalRoute();
}
/* Welcomes the user */
private void welcome() {
println("Welcome to Flight Planner");
println("Here is a list of all the cities in our database");
Iterator it = flights.getCities();
while(it.hasNext()) {
println(" " + it.next());
}
println("Let's plan a round-trip route!");
}
/* asks the user for the starting city and prints out
* all the possible destination cities for that city */
private void askForFistCity() {
while(true) {
firstCity = readLine("Enter the starting city: ");
if(flights.ContainsKey(firstCity)) {
enteredCities.add(firstCity);
break;
}
else{
println("You can't get to that city by a direct flight.");
println("Here is a list of all the cities in our
database");
Iterator it = flights.getCities();
while(it.hasNext()) {
println(" " + it.next());
}
}
}
println("From " + firstCity + " you can fly directly to:");
Iterator it = flights.findRoute(firstCity);
while(it.hasNext()) {
println(" " + it.next());
}
}
/* asks the user for the cities he/she wants to fly to,
* and prints out possible destination cities for each city
* until the user enters the starting city */
private void askForMoreCities() {
String city = firstCity;
String lastCity = city;
while(true) {
city = readLine("Where do you want to go from " + city + "?
");
if(city.equals(firstCity)) {
break;
}
if(flights.ContainsKey(city) == true) {
lastCity = city;
enteredCities.add(city);
}
else{
city = lastCity;
println("You can't get to that city by a direct flight.");
}
println("From " + city + " you can fly directly to:");
Iterator it = flights.findRoute(city);
while(it.hasNext()) {
println(" " + it.next());
}
}
}
/* prints out the chosen route */
private void printFinalRoute() {
println("The route you've chosen is");
String route = enteredCities.get(0);
for(int i = 1; i " + enteredCities.get(i);
}
route += " -> " + enteredCities.get(0);
println(route);
}
}

More Related Content

Similar to   import java.util.;import acm.program.;public class FlightPla.pdf

i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
armcomputers
 
Can you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfCan you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdf
FashionBoutiquedelhi
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
fonecomp
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
herminaherman
 
package reservation; import java.util.; For Scanner Class .pdf
 package reservation; import java.util.; For Scanner Class .pdf package reservation; import java.util.; For Scanner Class .pdf
package reservation; import java.util.; For Scanner Class .pdf
anitasahani11
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
clarkjanyce
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdf
poblettesedanoree498
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
Adamq0DJonese
 
I have compilation errors that I'm struggling with in my code- please.pdf
I have compilation errors that I'm struggling with in my code- please.pdfI have compilation errors that I'm struggling with in my code- please.pdf
I have compilation errors that I'm struggling with in my code- please.pdf
ColinjHJParsonsa
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdf
calderoncasto9163
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
anujmkt
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
ezzi552
 
app.js.docx
app.js.docxapp.js.docx
app.js.docx
armitageclaire49
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
apleather
 
I need to create a data type that implement the following interface -.docx
I need to create a data type that implement the following interface -.docxI need to create a data type that implement the following interface -.docx
I need to create a data type that implement the following interface -.docx
mckerliejonelle
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
rajkumari873
 

Similar to   import java.util.;import acm.program.;public class FlightPla.pdf (20)

i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
 
Can you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfCan you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdf
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
Implementation of c string functions
Implementation of c string functionsImplementation of c string functions
Implementation of c string functions
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
 
package reservation; import java.util.; For Scanner Class .pdf
 package reservation; import java.util.; For Scanner Class .pdf package reservation; import java.util.; For Scanner Class .pdf
package reservation; import java.util.; For Scanner Class .pdf
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdf
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
I have compilation errors that I'm struggling with in my code- please.pdf
I have compilation errors that I'm struggling with in my code- please.pdfI have compilation errors that I'm struggling with in my code- please.pdf
I have compilation errors that I'm struggling with in my code- please.pdf
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdf
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
week-3x
week-3xweek-3x
week-3x
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
 
app.js.docx
app.js.docxapp.js.docx
app.js.docx
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
 
week-5x
week-5xweek-5x
week-5x
 
I need to create a data type that implement the following interface -.docx
I need to create a data type that implement the following interface -.docxI need to create a data type that implement the following interface -.docx
I need to create a data type that implement the following interface -.docx
 
Quest 1 define a class batsman with the following specifications
Quest  1 define a class batsman with the following specificationsQuest  1 define a class batsman with the following specifications
Quest 1 define a class batsman with the following specifications
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 

More from anushasarees

Properties of enantiomers Their NMR and IR spec.pdf
                     Properties of enantiomers Their NMR and IR spec.pdf                     Properties of enantiomers Their NMR and IR spec.pdf
Properties of enantiomers Their NMR and IR spec.pdf
anushasarees
 
There are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdfThere are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdf
anushasarees
 
The main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdfThe main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdf
anushasarees
 
Successfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdfSuccessfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdf
anushasarees
 
SolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdfSolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdf
anushasarees
 
public class Team {Attributes private String teamId; private.pdf
public class Team {Attributes private String teamId; private.pdfpublic class Team {Attributes private String teamId; private.pdf
public class Team {Attributes private String teamId; private.pdf
anushasarees
 

More from anushasarees (20)

Properties of enantiomers Their NMR and IR spec.pdf
                     Properties of enantiomers Their NMR and IR spec.pdf                     Properties of enantiomers Their NMR and IR spec.pdf
Properties of enantiomers Their NMR and IR spec.pdf
 
O2 will be released as Na+ will not get reduce bu.pdf
                     O2 will be released as Na+ will not get reduce bu.pdf                     O2 will be released as Na+ will not get reduce bu.pdf
O2 will be released as Na+ will not get reduce bu.pdf
 
Huntingtons disease and other hereditary diseas.pdf
                     Huntingtons disease and other hereditary diseas.pdf                     Huntingtons disease and other hereditary diseas.pdf
Huntingtons disease and other hereditary diseas.pdf
 
ionic character BaF MgO FeO SO2 N2 .pdf
                     ionic character BaF  MgO  FeO  SO2  N2  .pdf                     ionic character BaF  MgO  FeO  SO2  N2  .pdf
ionic character BaF MgO FeO SO2 N2 .pdf
 
Nitrogen can hold up to 4 bonds. In sodium amide.pdf
                     Nitrogen can hold up to 4 bonds.  In sodium amide.pdf                     Nitrogen can hold up to 4 bonds.  In sodium amide.pdf
Nitrogen can hold up to 4 bonds. In sodium amide.pdf
 
C. hydrogen bonding. between N and H of differen.pdf
                     C. hydrogen bonding.  between N and H of differen.pdf                     C. hydrogen bonding.  between N and H of differen.pdf
C. hydrogen bonding. between N and H of differen.pdf
 
We Know that    Amines are generally basic in naturebecause of th.pdf
We Know that    Amines are generally basic in naturebecause of th.pdfWe Know that    Amines are generally basic in naturebecause of th.pdf
We Know that    Amines are generally basic in naturebecause of th.pdf
 
There are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdfThere are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdf
 
Three are ways to protect unused switch ports Option B,D and E is.pdf
Three are ways to protect unused switch ports Option B,D and E is.pdfThree are ways to protect unused switch ports Option B,D and E is.pdf
Three are ways to protect unused switch ports Option B,D and E is.pdf
 
The water turns green because the copper(II)sulfate is breaking apar.pdf
The water turns green because the copper(II)sulfate is breaking apar.pdfThe water turns green because the copper(II)sulfate is breaking apar.pdf
The water turns green because the copper(II)sulfate is breaking apar.pdf
 
The mutation is known as inversion. In this a segment from one chrom.pdf
The mutation is known as inversion. In this a segment from one chrom.pdfThe mutation is known as inversion. In this a segment from one chrom.pdf
The mutation is known as inversion. In this a segment from one chrom.pdf
 
The main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdfThe main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdf
 
Successfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdfSuccessfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdf
 
SolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdfSolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdf
 
Solutiona) Maximum bus speed = bus driver delay + propagation del.pdf
Solutiona) Maximum bus speed = bus driver delay + propagation del.pdfSolutiona) Maximum bus speed = bus driver delay + propagation del.pdf
Solutiona) Maximum bus speed = bus driver delay + propagation del.pdf
 
Solution Polymerase chain reaction is process in which several co.pdf
Solution Polymerase chain reaction is process in which several co.pdfSolution Polymerase chain reaction is process in which several co.pdf
Solution Polymerase chain reaction is process in which several co.pdf
 
Doubling [NO] would quadruple the rate .pdf
                     Doubling [NO] would quadruple the rate           .pdf                     Doubling [NO] would quadruple the rate           .pdf
Doubling [NO] would quadruple the rate .pdf
 
Correct answer F)4.0 .pdf
                     Correct answer F)4.0                            .pdf                     Correct answer F)4.0                            .pdf
Correct answer F)4.0 .pdf
 
D.) The system is neither at steady state or equi.pdf
                     D.) The system is neither at steady state or equi.pdf                     D.) The system is neither at steady state or equi.pdf
D.) The system is neither at steady state or equi.pdf
 
public class Team {Attributes private String teamId; private.pdf
public class Team {Attributes private String teamId; private.pdfpublic class Team {Attributes private String teamId; private.pdf
public class Team {Attributes private String teamId; private.pdf
 

Recently uploaded

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS Publications
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 

  import java.util.;import acm.program.;public class FlightPla.pdf

  • 1. import java.util.*; import acm.program.*; public class FlightPlanner extends ConsoleProgram { /* Private instance variables */ private FlightDB flights; //creates a new database private ArrayList enteredCities = new ArrayList(); //keeps track of entered cities private String firstCity; //keeps track of the first city entered by the user public void init() { //passes the text file to the database to read and parse flights = new FlightDB("flights.txt"); } public void run() { welcome(); askForFistCity(); askForMoreCities(); printFinalRoute(); } /* Welcomes the user */ private void welcome() { println("Welcome to Flight Planner"); println("Here is a list of all the cities in our database"); Iterator it = flights.getCities(); while(it.hasNext()) { println(" " + it.next()); } println("Let's plan a round-trip route!"); } /* asks the user for the starting city and prints out * all the possible destination cities for that city */ private void askForFistCity() {
  • 2. while(true) { firstCity = readLine("Enter the starting city: "); if(flights.ContainsKey(firstCity)) { enteredCities.add(firstCity); break; } else{ println("You can't get to that city by a direct flight."); println("Here is a list of all the cities in our database"); Iterator it = flights.getCities(); while(it.hasNext()) { println(" " + it.next()); } } } println("From " + firstCity + " you can fly directly to:"); Iterator it = flights.findRoute(firstCity); while(it.hasNext()) { println(" " + it.next()); } } /* asks the user for the cities he/she wants to fly to, * and prints out possible destination cities for each city * until the user enters the starting city */ private void askForMoreCities() { String city = firstCity; String lastCity = city; while(true) { city = readLine("Where do you want to go from " + city + "? "); if(city.equals(firstCity)) { break; } if(flights.ContainsKey(city) == true) { lastCity = city; enteredCities.add(city);
  • 3. } else{ city = lastCity; println("You can't get to that city by a direct flight."); } println("From " + city + " you can fly directly to:"); Iterator it = flights.findRoute(city); while(it.hasNext()) { println(" " + it.next()); } } } /* prints out the chosen route */ private void printFinalRoute() { println("The route you've chosen is"); String route = enteredCities.get(0); for(int i = 1; i " + enteredCities.get(i); } route += " -> " + enteredCities.get(0); println(route); } } import acm.program.*; public class FlightPlanner extends ConsoleProgram { /* Private instance variables */ private FlightDB flights; //creates a new database private ArrayList enteredCities = new ArrayList(); //keeps track of entered cities private String firstCity; //keeps track of the first city entered by the user public void init() { //passes the text file to the database to read and parse flights = new FlightDB("flights.txt");
  • 4. } public void run() { welcome(); askForFistCity(); askForMoreCities(); printFinalRoute(); } /* Welcomes the user */ private void welcome() { println("Welcome to Flight Planner"); println("Here is a list of all the cities in our database"); Iterator it = flights.getCities(); while(it.hasNext()) { println(" " + it.next()); } println("Let's plan a round-trip route!"); } /* asks the user for the starting city and prints out * all the possible destination cities for that city */ private void askForFistCity() { while(true) { firstCity = readLine("Enter the starting city: "); if(flights.ContainsKey(firstCity)) { enteredCities.add(firstCity); break; } else{ println("You can't get to that city by a direct flight."); println("Here is a list of all the cities in our database"); Iterator it = flights.getCities(); while(it.hasNext()) { println(" " + it.next());
  • 5. } } } println("From " + firstCity + " you can fly directly to:"); Iterator it = flights.findRoute(firstCity); while(it.hasNext()) { println(" " + it.next()); } } /* asks the user for the cities he/she wants to fly to, * and prints out possible destination cities for each city * until the user enters the starting city */ private void askForMoreCities() { String city = firstCity; String lastCity = city; while(true) { city = readLine("Where do you want to go from " + city + "? "); if(city.equals(firstCity)) { break; } if(flights.ContainsKey(city) == true) { lastCity = city; enteredCities.add(city); } else{ city = lastCity; println("You can't get to that city by a direct flight."); } println("From " + city + " you can fly directly to:"); Iterator it = flights.findRoute(city); while(it.hasNext()) { println(" " + it.next()); }
  • 6. } } /* prints out the chosen route */ private void printFinalRoute() { println("The route you've chosen is"); String route = enteredCities.get(0); for(int i = 1; i " + enteredCities.get(i); } route += " -> " + enteredCities.get(0); println(route); } } Solution import java.util.*; import acm.program.*; public class FlightPlanner extends ConsoleProgram { /* Private instance variables */ private FlightDB flights; //creates a new database private ArrayList enteredCities = new ArrayList(); //keeps track of entered cities private String firstCity; //keeps track of the first city entered by the user public void init() { //passes the text file to the database to read and parse flights = new FlightDB("flights.txt"); } public void run() { welcome(); askForFistCity(); askForMoreCities(); printFinalRoute();
  • 7. } /* Welcomes the user */ private void welcome() { println("Welcome to Flight Planner"); println("Here is a list of all the cities in our database"); Iterator it = flights.getCities(); while(it.hasNext()) { println(" " + it.next()); } println("Let's plan a round-trip route!"); } /* asks the user for the starting city and prints out * all the possible destination cities for that city */ private void askForFistCity() { while(true) { firstCity = readLine("Enter the starting city: "); if(flights.ContainsKey(firstCity)) { enteredCities.add(firstCity); break; } else{ println("You can't get to that city by a direct flight."); println("Here is a list of all the cities in our database"); Iterator it = flights.getCities(); while(it.hasNext()) { println(" " + it.next()); } } } println("From " + firstCity + " you can fly directly to:"); Iterator it = flights.findRoute(firstCity); while(it.hasNext()) { println(" " + it.next()); }
  • 8. } /* asks the user for the cities he/she wants to fly to, * and prints out possible destination cities for each city * until the user enters the starting city */ private void askForMoreCities() { String city = firstCity; String lastCity = city; while(true) { city = readLine("Where do you want to go from " + city + "? "); if(city.equals(firstCity)) { break; } if(flights.ContainsKey(city) == true) { lastCity = city; enteredCities.add(city); } else{ city = lastCity; println("You can't get to that city by a direct flight."); } println("From " + city + " you can fly directly to:"); Iterator it = flights.findRoute(city); while(it.hasNext()) { println(" " + it.next()); } } } /* prints out the chosen route */ private void printFinalRoute() { println("The route you've chosen is"); String route = enteredCities.get(0); for(int i = 1; i " + enteredCities.get(i); }
  • 9. route += " -> " + enteredCities.get(0); println(route); } } import acm.program.*; public class FlightPlanner extends ConsoleProgram { /* Private instance variables */ private FlightDB flights; //creates a new database private ArrayList enteredCities = new ArrayList(); //keeps track of entered cities private String firstCity; //keeps track of the first city entered by the user public void init() { //passes the text file to the database to read and parse flights = new FlightDB("flights.txt"); } public void run() { welcome(); askForFistCity(); askForMoreCities(); printFinalRoute(); } /* Welcomes the user */ private void welcome() { println("Welcome to Flight Planner"); println("Here is a list of all the cities in our database"); Iterator it = flights.getCities(); while(it.hasNext()) { println(" " + it.next()); } println("Let's plan a round-trip route!"); }
  • 10. /* asks the user for the starting city and prints out * all the possible destination cities for that city */ private void askForFistCity() { while(true) { firstCity = readLine("Enter the starting city: "); if(flights.ContainsKey(firstCity)) { enteredCities.add(firstCity); break; } else{ println("You can't get to that city by a direct flight."); println("Here is a list of all the cities in our database"); Iterator it = flights.getCities(); while(it.hasNext()) { println(" " + it.next()); } } } println("From " + firstCity + " you can fly directly to:"); Iterator it = flights.findRoute(firstCity); while(it.hasNext()) { println(" " + it.next()); } } /* asks the user for the cities he/she wants to fly to, * and prints out possible destination cities for each city * until the user enters the starting city */ private void askForMoreCities() { String city = firstCity; String lastCity = city; while(true) { city = readLine("Where do you want to go from " + city + "? "); if(city.equals(firstCity)) {
  • 11. break; } if(flights.ContainsKey(city) == true) { lastCity = city; enteredCities.add(city); } else{ city = lastCity; println("You can't get to that city by a direct flight."); } println("From " + city + " you can fly directly to:"); Iterator it = flights.findRoute(city); while(it.hasNext()) { println(" " + it.next()); } } } /* prints out the chosen route */ private void printFinalRoute() { println("The route you've chosen is"); String route = enteredCities.get(0); for(int i = 1; i " + enteredCities.get(i); } route += " -> " + enteredCities.get(0); println(route); } }