Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Encode this information and: Write a prolog program that checks if there is a ro

ID: 3771768 • Letter: E

Question

Encode this information and: Write a prolog program that checks if there is a route between two given cites. For example, a sample test run could be: flight (fresno, o maha). True Flight (o maha, fr esno). False. Write a programs using an imperative language of your choice that checks if there is a route between two given cites. The cities will be provided as runtime arguments for an executable file (e.g., .exe, .jar). For example, if used Java, a sample test run could be: >java-jar prog3b. jar flight(fresno, o maha) true >java -jar prog3b.jar flight(o maha, fr esno) false.

Explanation / Answer

package cityroutechecker;
import java.util.Scanner;


public class CityRouteChecker {

  
    public static boolean flight(String src, String dest)    {
        boolean routeExist = false;
        if ("Seattle".equals(src)) {
            if ("Omaha".equals(dest)) routeExist = true;
            if ("Dallas".equals(dest)) routeExist = true;
            return routeExist;  
        } // end if of src = Seattle
        if ("Omaha".equals(src)) {
            if ("Albany".equals(dest)) routeExist = true;
            if ("Atlanta".equals(dest)) routeExist = true;
        } // end if of Omaha
        if ("Albany".equals(src))   {
            if ("Albany".equals(dest)) routeExist = true;
        } // end albny as src
        // no flights originate from Boston, Hence Boston is never a source
        // move on to Atlanta as source
        if ("Atlanta".equals(src))   {
            if ("Dallas".equals(dest)) routeExist = true;
            if ("Boston".equals(dest)) routeExist = true;
        } // end atl src
        if ("Dallas".equals(src))   {
            if ("Albany".equals(dest)) routeExist = true;
            if ("Seattle".equals(dest)) routeExist = true;
          
          
        } // end dallas src
        if ("Fresno".equals(src))   {
                        if ("Seattle".equals(dest)) routeExist = true;
            if ("Albany".equals(dest)) routeExist = true;                      
                        if ("Boston".equals(dest)) routeExist = true;
          
        }
      
        return false;
    } // end func flight
    public static void userInputGetter()   {
        String sourceCity = " ", desitinationCity = " ";
        Scanner sc = new Scanner(System.in);
        sourceCity = sc.next();
        desitinationCity = sc.next();
        System.out.println("Source city = " + sourceCity);
        System.out.println("Destination city = " + desitinationCity);
        //flight(sourceCity, destinationCity);
      
      
      
    } // end func
  
    public static void main(String[] args) {

        userInputGetter();      // call function
        System.out.println(flight("Seattle", "Omaha"));
        System.out.println(flight("Seattle", "Dallas"));
        System.out.println(flight("Seattle", "Texas"));

      
  
  
  
    } // end main
  
} // end public class City Route Checker

run:
Albany
Boston
Source city = Albany
Destination city = Boston
true
true
false
BUILD SUCCESSFUL (total time: 12 seconds)

Dr Jack
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote