import javautilScannerimport javautilComparator import Essay

// import java.util.Scanner;

//import java.util.Comparator;

//import java.util.Map;

//import java.util.Set;

//import java.util.TreeMap;

import java.lang.*;

import java.util.*;

abstract class Graph{

private String source;

private String destination;

private String roadType;

private String name;

private int length;

private int maxSpeed;

private double effectiveSpeed;

private double cost;

Graph(String data[])

{

this.source = data[0];

this.destination = data[1];

this.roadType = data[2];

this.name = data[3];

this.length = Integer.parseInt(data[4]);

this.maxSpeed = Integer.parseInt(data[5]);

}

// public void findCost();

// public void findEffectiveSpeed();

// GETTER METHODS

public String getSource()

{

return this.source;

}

public String getDestination()

{

return this.destination;

}

public String getName()

{

return this.name;

}

public int getMaxSpeed()

{

return this.maxSpeed;

}

public int getLength()

{

return this.length;

}

public double getCost()

{

return this.cost;

}

public double getEffectiveSpeed()

{

return this.effectiveSpeed;

}

// function to find cost

void findCost()

{

this.cost = (this.length/(this.effectiveSpeed*1.0));

}

//SETTER METHODS

public void setMaxSpeed(int maxSpeed)

{

this.maxSpeed = maxSpeed;

}

public void setLength(int length)

{

this.length = length;

}

public void setName(String name )

{

this.name = name;

}

public void setEffectiveSpeed(double effectiveSpeed)

{

this.effectiveSpeed = effectiveSpeed;

}

public void setCost(double cost)

{

this.cost=cost;

}

}

class motorway extends Graph{

private int tollPrice;

private int lanes;

private int maintenance;

private int occupancy;

private int maxOccupancy;

motorway(String data[])

{

super(data);

this.tollPrice = Integer.parseInt(data[6]);

this.lanes = Integer.parseInt(data[7]);

this.maintenance = Integer.parseInt(data[8]);

this.occupancy = Integer.parseInt(data[9]);

this.maxOccupancy = 100;

findEffectiveSpeed();

findCost();

}

void findEffectiveSpeed()

{

this.setEffectiveSpeed(this.getMaxSpeed()*(1.0- occupancy/(maxOccupancy*1.0*lanes)));

//return effectiveSpeed;

}

public String toString()

{

return ( this.getName()+ ” “+ this.getLength()+” “+ this.getMaxSpeed()+” “+tollPrice

+” “+lanes +” “+ maintenance +” “+ occupancy);

}

}

class pedestrianRoad extends Graph{

private int width;

private int scenicValue;

private int occupancy;

private int maxOccupancy;

pedestrianRoad(String data[])

{

super(data);

this.width = Integer.parseInt(data[6]);

this.scenicValue = Integer.parseInt(data[7]);

this.occupancy = Integer.parseInt(data[8]);

this.maxOccupancy = 1500;

findEffectiveSpeed();

findCost();

}

void findEffectiveSpeed()

{

this.setEffectiveSpeed(this.getMaxSpeed()*(1.0- occupancy/(maxOccupancy*1.0)));

//return effectiveSpeed;

}

public String toString()

{

return ( this.getName()+ ” “+ this.getLength()+” “+ this.getMaxSpeed()

+” “+width +” “+ scenicValue +” “+ occupancy);

}

}

class cyclistRoad extends Graph{

private int curvature;

cyclistRoad(String data[])

{

super(data);

this.curvature = Integer.parseInt(data[6]);

findEffectiveSpeed();

findCost();

}

void findEffectiveSpeed(){

this.setEffectiveSpeed(this.getMaxSpeed()/(curvature*1.0));

//return effectiveSpeed;

}

public String toString()

{

return ( this.getName()+ ” “+ this.getLength()+” “+ this.getMaxSpeed()+” “+curvature);

}

}

class swamps extends Graph{

private int difficulty;

swamps(String data[])

{

super(data);

this.difficulty = Integer.parseInt(data[6]);

findEffectiveSpeed();

findCost();

}

void findEffectiveSpeed()

{

this.setEffectiveSpeed(this.getMaxSpeed()/(difficulty * difficulty*1.0));

// return effectiveSpeed;

}

public String toString()

{

return ( this.getName()+ ” “+ this.getLength()+” “+ this.getMaxSpeed()+” “+difficulty);

}

}

class lakes extends Graph{

private int width;

private int tidalLevel;

private int depth;

lakes(String data[])

{

super(data);

this.width = Integer.parseInt(data[6]);

this.tidalLevel = Integer.parseInt(data[7]);

this.depth = Integer.parseInt(data[8]);

findEffectiveSpeed();

findCost();

}

void findEffectiveSpeed()

{

this.setEffectiveSpeed(this.getMaxSpeed());

// return effectiveSpeed;

}

public String toString()

{

return ( this.getName()+ ” “+ this.getLength()+” “+ this.getMaxSpeed()

+” “+width +” “+ tidalLevel +” “+ depth);

}

}

class sortComparator implements Comparator

{

public int compare(Graph path1,Graph path2)

{

if( path1.getCost()-path2.getCost()>=0.0001)

return 1;

else if(Math.abs(path1.getCost()-path2.getCost()) < 0.0001 )

return path1.getName().compareTo(path2.getName());

else return -1;

}

}

class makeGraph{

private TreeMap graphlist;

private int n;

makeGraph(int n)

{

this.n=n;

graphlist = new TreeMap();

}

void addEdge(Graph path)

{

String source= path.getSource();

String destination = path.getDestination();

if(graphlist.containsKey(source))

{

ArrayList list= graphlist.get(source);

list.add(path);

graphlist.put(source,list);

}

else

{

ArrayList list= new ArrayList();

list.add(path);

graphlist.put(source,list);

}

if(graphlist.containsKey(destination))

{

ArrayList list= graphlist.get(destination);

list.add(path);

graphlist.put(destination,list);

}

else

{

ArrayList list= new ArrayList();

list.add(path);

graphlist.put(destination,list);

}

}

TreeMap getgraphlist()

{

return graphlist;

}

void sortFunc()

{

for( Map.Entry entry : graphlist.entrySet() )

{

ArrayList path = (ArrayList ) entry.getValue();

Collections.sort(path, new sortComparator());

}

}

void modifyEdge(String data[])

{

Graph path;

if(data[2].equals(“motorway”))

{

path=new motorway(data);

}

else if(data[2].equals(“pedestrianRoad”))

{

path=new pedestrianRoad(data);

}

else if(data[2].equals(“cyclistRoad”))

{

path=new cyclistRoad(data);

}

else if(data[2].equals(“swamps”))

{

path=new swamps(data);

}

else

{

path=new lakes(data);

}

addEdge(path);

}

}

class print

{

public static void printGraph(TreeMap graphlist)

{

for( Map.Entry val : graphlist.entrySet() )

{

String key = (String) val.getKey();

ArrayList path = (ArrayList ) val.getValue();

Iterator it = path.listIterator();

while ( it.hasNext() )

{

Graph g= (Graph)it.next();

if(g.getSource().compareTo(key) == 0)

System.out.println( key +” “+ g.getDestination()+” “+g);

else

System.out.println(key +” “+ g.getSource()+” “+g);

}

}

}

}

public class Roadnetwork1{

public static void main(String[] args)

{

Scanner obj= new Scanner(System.in);

int t=obj.nextInt();

for(int j=0;j

Still stressed from student homework?
Get quality assistance from academic writers!