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

📄 train.java

📁 贪食蛇的实现源码
💻 JAVA
字号:
package test;
/*写一个 地铁类, 如 地铁名称, 卡号,出发站台,结束站台,乘坐时间
经过的路线1.经过的路线2
统计乘坐最多的路线
(如13号线,1号线,2号线,计算那个线路乘坐的顾客最多)
*/
public class Train 
{
	private String trainName;
	private int cardId;
	private int beginBoard;
	private int endBoard;
	private String time;
	private int[] pathId;

	 public int getCardId() {
		return cardId;
	}
   public void setCardId(int cardId) {
		this.cardId = cardId;
	}
   public int[] getPathId() {
		return pathId;
	}
   public void setPathId(int[] pathId) {
		this.pathId = pathId;
	}


public Train() {}
public Train(String trainName, int cardId, int beginBoard, int endBoard, String time, int[] pathId) 
	  {
		this.trainName = trainName;
		this.cardId = cardId;
		this.beginBoard = beginBoard;
		this.endBoard = endBoard;
		this.time = time;
		this.pathId = pathId;
	   }
 public static void main(String[] args)
  {
	//  Train tra=new Train();
	  int[] s1={1,2,13};
	  int[] s2={2,13,0};
	  int[] s3={2,1,0};
	  int[] s4={1,0,0};
	  int[] s5={13,0,0};
	  int[] s6={1,13,0};
	  
   Train[] train={
		           new Train("城铁",123456,1,2,"2008.7.15",s1),
			       new Train("城铁",234567,1,2,"2008.7.15",s2),
			       new Train("地铁",345678,1,2,"2008.7.19",s3),
			       new Train("地铁",456789,1,2,"2008.7.15",s4),
			       new Train("城铁",123450,1,2,"2008.7.16",s5),
			       new Train("城铁",234560,1,2,"2008.7.21",s6)
	             };//不支持此类形式:new Train("城铁",123456,1,2,"2008.7.15",{1,2,13}),
     // int[] a =new int[3];
      int[] a;
      int b=0;
      int c=0;
      int d=0;
      //train[i].getClass()=??
      for(int i=0;i<train.length;i++)
      {
    	 a=train[i].getPathId();
    	  for(int j=0;j<a.length;j++)
    	  {
    		  if(a[j]==1)
    			  b++;
    			  else if(a[j]==2)
    				  c++;
    			         else if(a[j]==13)
    				        d++;
    			               else break;//有必要么?
    		  //System.out.println("13号线乘坐人数:"+d);
    	   }
    	  //System.out.println("1号线乘坐人数:"+b);
      }
    	  System.out.println("1号线乘坐人数:"+b);
    	  System.out.println("2号线乘坐人数:"+c); 
    	  System.out.println("13号线乘坐人数:"+d);
	}
	
}

⌨️ 快捷键说明

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