+1 (315) 557-6473 

Program To Implement a Campus Tour Using Java Programming Language Assignment Solution.


Instructions

Objective
We can assist your java assignment to implement a campus tour using the Java programming language. In this program, we'll create a user-friendly interface to guide visitors through the campus, providing information about different locations and facilities. Using Java's object-oriented features, we'll design classes for each location, allowing users to navigate seamlessly. Additionally, we'll incorporate interactive features like user input to enhance the tour experience. Gain a better understanding of programming concepts while creating a practical and engaging campus tour application.

Requirements and Specifications

Implement campus tour program using Java programming language
Implement campus tour program using Java programming language 1
Implement campus tour program using Java programming language 2
Implement campus tour program using Java programming language 3
Implement campus tour program using Java programming language 4

Source Code

CAMPUS

import java.util.HashMap;

public class Campus {

    private String campusName;

    private HashMap locations;

    private Location startingLocation;

    private String filename;

    public Campus() {

        this.campusName = null;

        this.locations = new HashMap<>();

        this.startingLocation = null;

        this.filename = null;

    }

    public Campus(String campusName, Location startingLocation) {

        this.campusName = campusName;

        this.locations = new HashMap<>();

        this.startingLocation = startingLocation;

        this.filename = null;

    }

    public void addLocation(Location location) {

        locations.put(location.getName(), location);

    }

    public Location getLocation(String name) {

        return locations.get(name);

    }

    public void removeLocation(String name) {

        locations.remove(name);

    }

    public String getCampusName() {

        return campusName;

    }

    public void setCampusName(String campusName) {

        this.campusName = campusName;

    }

    public Location getStartingLocation() {

        return startingLocation;

    }

    public void setStartingLocation(Location startingLocation) {

        this.startingLocation = startingLocation;

    }

    public String getFilename() {

        return filename;

    }

    public void setFilename(String filename) {

        this.filename = filename;

    }

}

DOOR

public class Door {

    private String direction;

    private Location leavingLocation;

    private Location enteringLocation;

    public Door() {

        this.direction = null;

        this.leavingLocation = null;

        this.enteringLocation = null;

    }

    public Door(String direction, Location leavingLocation, Location enteringLocation) {

        this.direction = direction;

        this.leavingLocation = leavingLocation;

        this.enteringLocation = enteringLocation;

    }

    public String describe() {

        return "You can go " + direction.toUpperCase() + " to get to " + enteringLocation.getName();

    }

    public Location getLeaving() {

        return leavingLocation;

    }

    public void setLeaving(Location leaving) {

        leavingLocation = leaving;

    }

    public Location getEntering() {

        return enteringLocation;

    }

    public void setEntering(Location entering) {

        enteringLocation = entering;

    }

    public String getDirection() {

        return direction;

    }

    public void setDirection(String direction) {

        this.direction = direction;

    }

}

LOCATION

import java.util.ArrayList;

public class Location {

    private String name;

    private String description;

    private Boolean haveVisited;

    private ArrayList doors;

    public Location() {

        this.name = null;

        this.description = null;

        this.haveVisited = false;

        this.doors = new ArrayList<>();

    }

    public Location(String name, String description) {

        this.name = name;

        this.description = description;

        this.haveVisited = false;

        this.doors = new ArrayList<>();

    }

    public String getName() {

        return name;

    }

    public void setName(String name) {

        this.name = name;

    }

    public String getDescription() {

        return description;

    }

    public void setDescription(String description) {

        this.description = description;

    }

    public ArrayList getDoors() {

        return doors;

    }

    public Location leaveLocation(String dir) {

        return doors.stream().filter(d -> d.getDirection().equals(dir)).map(Door::getEntering).findAny().orElse(null);

    }

    public void addDoor(Door door) {

        doors.add(door);

    }

    public boolean visit() {

        boolean result = haveVisited;

        haveVisited = true;

        return result;

    }

}

TOUR STATUS

public class TourStatus {

    private Campus campus;

    private Location currentLocation;

    public TourStatus() {

        this.campus = null;

        this.currentLocation = null;

    }

    public Campus getCampus() {

        return campus;

    }

    public void setCampus(Campus campus) {

        this.campus = campus;

    }

    public Location getCurrentLocation() {

        return currentLocation;

    }

    public void setCurrentLocation(Location currentLocation) {

        this.currentLocation = currentLocation;

    }

    public void updateTourLocation(String dir) {

        if (currentLocation != null) {

            Location result = currentLocation.leaveLocation(dir);

            if (result != null) {

                currentLocation = currentLocation.leaveLocation(dir);

                if (!currentLocation.visit()) {

                    System.out.println("Welcome to " + currentLocation.getName());

                    System.out.println(currentLocation.getDescription());

                }

            }

            else {

                System.out.println("Invalid direction");

            }

        }

    }

}

TOUR UMW

import java.io.File;

import java.io.IOException;

import java.util.Scanner;

public class TourUMW {

    private static final String SEP1 = "*****";

    private static final String SEP2 = "+++";

    private static final String INPUT_FILENAME = "input.txt";

    private static Campus campus;

    private static TourStatus status;

    public static void main(String[] args) {

        Campus campus = null;

        try (Scanner scanner = new Scanner(new File(INPUT_FILENAME))) {

            campus = setUpCampus(scanner);

        }

        catch (IOException e) {

            throw new RuntimeException(e);

        }

        System.out.println("You are visiting " + campus.getCampusName());

        System.out.println();

        TourStatus status = new TourStatus();

        status.setCampus(campus);

        status.setCurrentLocation(campus.getStartingLocation());

        status.getCurrentLocation().visit();

        System.out.println("Welcome to " + campus.getStartingLocation().getName());

        System.out.println(campus.getStartingLocation().getDescription());

        System.out.println();

        Scanner scanner = new Scanner(System.in);

        boolean isOver = false;

        while (!isOver) {

            System.out.println("You are at " + status.getCurrentLocation().getName() + " now");

            for (Door d : status.getCurrentLocation().getDoors()) {

                System.out.println(d.describe());

            }

            System.out.println("Print 'Q' to quit");

            System.out.print("Your choice: ");

            String choice = promptUser(scanner);

            if ("q".equals(choice)) {

                isOver = true;

            } else {

                status.updateTourLocation(choice);

            }

            System.out.println();

        }

        System.out.println("Thank you for visiting " + campus.getCampusName());

        scanner.close();

    }

    public static Campus setUpCampus(Scanner input) {

        Campus campus = new Campus();

        String line;

        String campusName = input.nextLine().trim();

        line = input.nextLine().trim();

        assert SEP1.equals(line);

        campus.setCampusName(campusName);

        Location startingLocation = null;

        line = input.nextLine().trim();

        assert "Locations:".equals(line);

        while(true) {

            String name = input.nextLine().trim();

            if (SEP1.equals(name)) {

                break;

            }

            String description = input.nextLine().trim();

            Location location = new Location(name, description);

            if (startingLocation == null) {

                startingLocation = location;

            }

            campus.addLocation(location);

            line = input.nextLine().trim();

            assert SEP2.equals(line);

        }

        campus.setStartingLocation(startingLocation);

        assert "Doors:".equals(input.nextLine().trim());

        while(true) {

            String loc1 = input.nextLine().trim();

            if (SEP1.equals(loc1)) {

                break;

            }

            String dir = input.nextLine().trim();

            String loc2 = input.nextLine().trim();

            Location l1 = campus.getLocation(loc1);

            Location l2 = campus.getLocation(loc2);

            l1.addDoor(new Door(dir, l1, l2));

            line = input.nextLine().trim();

            assert SEP2.equals(line);

        }

        return campus;

    }

    public static String promptUser(Scanner input) {

        return input.nextLine().trim().toLowerCase();

    }

}