⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 busroute.java

📁 A part public bus simulation system, mainly about map design, java file, groupwork, helpful to the b
💻 JAVA
字号:
//Written by Jeffrey Liu
//Before adding a point to bus route
//isInterchage(Point) & isOnRoad(Point) need to be checked by GUI
//these two are methods provided by mapData class
//then GUI need to set isDepot or set isOnRoad, if isInterchage(Point) or isOnRoad(Point)
//returns a true value 

package tools;
import java.awt.Point;
import java.util.LinkedList;

public class BusRoute extends Tools {
	private LinkedList tempRoute;
	private int busNum;
	private boolean complete;                   //Whether the bus route is completely built
	private boolean isDepot;              //is the point passed in an Depot
	private boolean isOnRoad;                   //is the point passed in on a road
	
	//Creates a new instance of BusRoute 
	 
	public BusRoute() {
		tempRoute = new LinkedList();
		busNum = 0;
		complete = false;
		isDepot = false;
		isOnRoad = false;
		super.setID(12);
	}
	
	//The boolean value returned means whether successfully add a point to the bus route 
	 
	public boolean addPoint(Point cursorPoint) {
		boolean status=false; //by default, function returns false
		//check if point is on road
		//if (isOnRoad) {
			//is on road,check if it's empty
			if (tempRoute.isEmpty()) {
				//tempRoute is empty
				//check if point is bus Depot
				if (isDepot) {
					//is Depot, proceed to add point
					tempRoute.add(cursorPoint);
					status = true; //set to return true
				}
			} else { 
                    
				//tempRoute is not empty
				//check if point is adjacent to last point
				Point lastPoint = (Point) tempRoute.getLast();
				if((Math.abs((int)cursorPoint.getX() - (int)lastPoint.getX())) + 
						(Math.abs((int)cursorPoint.getY() - (int)lastPoint.getY())) == 1) {
					//is adjacent point						
					tempRoute.add(cursorPoint);
					status = true; //set to return true
					
					//check if it's Depot
					if (isDepot) {
						//is Depot, last point of busRoute
						complete = true;
					}
				} 				
			}
		//}
		isDepot=false;//prepare for next addPoint
		isOnRoad= false; //prepare for next addPoint
		return status;
		
	}
	
	
	//If the point is the last one on the route, remove it and return true
	
	public boolean removePoint(Point cursorPoint) {
		if(cursorPoint == tempRoute.getLast()) {
			tempRoute.removeLast();
			return true;
		}
		else return false;
	}
	
	//Check whether the bus route is built completely
	 
	public boolean isComplete() {
		return complete;
	}
	
	//Get a point, index starts from 0
	 
	public Point getPoint(int index) {
		return (Point)tempRoute.get(index);
	}
	
	//Get length of bus route
	
	public int getLength() {
		return tempRoute.size();
	}
	
	//Check whether a point is on the route
	
	public boolean contains(Point cursorPoint) {
		return tempRoute.contains(cursorPoint);
	}
	
	//Set bus number
	
	public void setBusNum(int busNum) {
		this.busNum = busNum;
	}
	
	//Get bus number
	
	public int getBusNum() {
		return busNum;
	}
	
	//Set when the point passed in is an Depot
	 
	public void setIsDepot() {
		isDepot = true;
	}
	
	//Set when the point passed in is on a road
	 
	public void setisOnRoad() {
		isOnRoad = true;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -