[英]Anylogic - Delay block for parking
有沒有人知道如何獲得 function 的值,該值指示街區是否有空停車位。 我正在使用隊列,我嘗試了 function nFree nFree()
和spaceIndex()
,但我知道這兩個函數沒有為該類型定義
希望我理解您的問題,下面是可能返回所有停車位的代碼。
public class Parking {
static int parkingSize = 10;
static Object[] object = new Object[parkingSize];
public static void main(String[] args) {
add("java", 10);
System.out.println(checkEmptyParkingSpot());
emptyParkingSpot(10);
System.out.println(checkEmptyParkingSpot());
}
// add the object in specicif location
public static void add(String info, int position) {
// if the position does not exist an erro will be thow
if (position > object.length ) {
throw new RuntimeException("The possition indicated does not exist in the park");
}
if (object[position - 1] != null) {
throw new RuntimeException("The possition is ocupied");
}
object[position - 1] = info;
}
// to remove an object from the park and free the space
public static void emptyParkingSpot(int position) {
if (position > object.length ) {
throw new RuntimeException("The possition indicated does not exist in the park");
}
if (object[position - 1] == null) {
throw new RuntimeException("The possition isalready empty");
}
object[position - 1] = null;
}
// lists the empty spot
public static String checkEmptyParkingSpot() {
String emptySpace = "".trim();
for (int i = 0; i < object.length; i++) {
// list the empty space
if (object[i] == null) {
emptySpace = emptySpace + (i + 1) + "\n";
}
}
// if there is no space the message will be park full
if (emptySpace.isEmpty()) {
emptySpace = "Park is Full";
}
return emptySpace;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.