SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 313 Weeks Ago, 6 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 13 Nov 2017 My Price 10.00

how to write path and getnextCity method

map.java for cs 2003 project3. how to write path and getnextCity method

import java.io.*;
import java.util.*;
/*
 * Created on Oct 13, 2004
 * @author class_sandip
 */
public class Map {
    private ListInterface<City> adjList;

    public Map(String mapFileName) {
    adjList = new ListReferenceBased<City>();
    createFlightMap(mapFileName);
    }
    public void createFlightMap(String mapFileName) {
    try {
        Scanner input = new Scanner(new File(mapFileName));
        Scanner line;
        while (input.hasNextLine()){
        line = new Scanner(input.nextLine());
        String origCity = line.next();
        City ct = getCity(origCity);
        if (ct==null) {
            ct = new City(origCity);
            adjList.append(ct);
        }
        String destCity = line.next();
        if(getCity(destCity)==null)
            adjList.append(new City(destCity));
        double cost = line.nextDouble();
        ct.addNeighbor(new Destination(destCity, cost));
        }
        input.close();
    } catch (IOException e) {
        System.out.println("IOException in reading input file!!!");
    }
    }
    public void unvisitAll() {
    for (int i = 1; i <= adjList.size(); i++){
        City ct =  adjList.get(i);
        ct.unmarkVisited();
        ct.resetNext();
    }   
    }

    // Use contains on adjList to return the City with name cityName
    // if it exists in the map, otherwise return null.
    public City getCity(String cityName) {
    // NEED CODE FOR PROJECT
        City city = new City(cityName);
        if(adjList.contains(city)==-1)
            return null;
        else
            return city;
       
           
    }

    public City getNextCity(City ct) {
    // If there are more neighbors to visit from ct,
    // loop
    //   get name of next neighbor
    //   retrieve the City with that name
    //   if that City is unvisited return it
    //
    // if no unvisited neighbor of ct remains, return null
   
    // NEED CODE FOR PROJECT
    }
    public void findPath(String origin, String destination) {
    //       ---------------------------------------------------
    //       Determines whether a sequence of flights between
    //       two cities exists. Nonrecursive stack version.
    //       Precondition: origin and destination are the origin
    //       and destination city names, respectively.
    //       Postcondition: Prints out a sequence of flights
    //       connecting origin to destination and the total
    //       cost, otherwise prints out a failure
    //       message. Cities visited during search are marked as
    //       visited in the flight map.  Implementation notes:
    //       Uses a stack for the cities of a potential
    //       path. Calls unvisitAll, markVisited, and
    //       getNextCity.
    //       ---------------------------------------------------

    City originCity = getCity(origin);
    if (originCity == null)
        System.out.println("No flights from " + origin);
    else {
        City destinationCity = new City(destination);
        StackInterface<City> stack = new StackVectorBased<City>();
      
        // NEED CODE FOR PROJECT
        // Use stack to search the map and if path is found,
        // print out the path and the total cost
    }
    } // end isPath
}

Answers

(5)
Status NEW Posted 13 Nov 2017 12:11 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)