/**
*
* author douglas
* Created by douglas on 1/21/16.
*/
package com.douglas.ticketmanager;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import android.widget.Toast;
import com.dewav.ticket.ITicketManager;
import java.util.*;
import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
public class DouglasService extends Service {
private final static String TAG = "com.douglas.ticketmanager.DouglasService";
private int[][][] startArray = new int[500][12][2];
private int currentSeat = 0;/*1-----500*/
private int currentTicketNum = 0;/*1-----6000*/
private static final int CLIENT_MAX = 3;
private static final int SEATS_MAX = 50;
private static final int TRAIN_MAX = 10;
private static final int SEARS_MAX = (SEATS_MAX * TRAIN_MAX);
private static final int STATION_MAX = 13;
private static final int STATION_ONE_TRAIN_MAX = (STATION_MAX -1);
private static final int TICKETS_MAX = (SEATS_MAX * TRAIN_MAX * (STATION_MAX - 1)) ;
public void onCreate() {
super.onCreate();
initTicketStrure();
}
public void initTicketStrure(){
Log.d(TAG, "initTicketStrure begin!");
for (int seat = 0; seat < SEARS_MAX; seat++) {
for (int i = 0; i < STATION_ONE_TRAIN_MAX; i++) {
for (int j = 0; j < 2; j++) {
startArray[seat][i][j]= 0;
}
}
}
Log.d(TAG, "initTicketStrure end!");
}
public String checkStation1(String Station) {
//Log.d(TAG, "checkStation1");
String sub="S";
int result = Station.indexOf(sub);
Log.d(TAG, "result :" + result);
String myStation = null;
/*
* Exclude illegal character
* */
if (result >= 0 ) {
myStation = Station.substring(1);
Log.d(TAG, "myStation" + myStation);
return myStation;
}else{
Log.d(TAG, "return null;");
return null;
}
}
public int checkStation2(String Station) {
//Log.d(TAG, "checkStation2");
int myStation = 0;
/*
* Exception Handling
* */
try {
myStation = Integer.parseInt(Station);
Log.d(TAG, "myStation" + myStation);
return myStation;
} catch (Exception e) {
Log.d(TAG, "return 0!");
return 0;
}
}
public boolean JudgeParameters(int number, String departureStation, String terminus) {
//Log.d(TAG, "JudgeParameters");
int startStation = 0;
int endStation = 0;
Message msg = new Message();
msg.what = 0;
if (number != 0) {
if (number <= 0 || number > 500) {//1-500
msg.obj = "The number must be Greater than zero or Less than 500!";
myHandler.sendMessage(msg);
//Log.d(TAG, "The number must be Greater than zero or Less than 500!");
return false;
}
else if (number == 1234) {
initTicketStrure();
//Log.d(TAG, "Clean Up SationList!");
return false;
}
} else {
msg.obj = "The number must a valid number from 1 to 500!";
myHandler.sendMessage(msg);
//Log.d(TAG, "The number must a valid number from 1 to 500!");
} /*
* Exclude illegal character
* */
departureStation = checkStation1(departureStation);
terminus = checkStation1(terminus);
if (departureStation == null || terminus == null) {
msg.obj = "Please enter a valid station! Format S+digital!";
myHandler.sendMessage(msg);
//Log.d(TAG, "departureStation == null || terminus == null " + "\n" + " return false !");
return false;
}
/*
* Exception Handling
* */
startStation = checkStation2(departureStation);
endStation = checkStation2(terminus);
if (startStation == 0 || endStation == 0) {
msg.obj = "\"Please enter a valid station! Format S+digital!\"";
myHandler.sendMessage(msg);
Log.d(TAG, "startStation == 0 || endStation == 0 ---- return false!");
return false;
}
/* Check */
if (startStation <= 0 || startStation > 13 || endStation <= 0 || endStation > 13 ) {//1-13
msg.obj = "The station must be Greater than S1 or Less than S13!";
myHandler.sendMessage(msg);
Log.d(TAG, "The station must be Greater than S1 or Less than S13!");
} else if (startStation >= endStation) {
msg.obj = "Please enter a valid station! startStation must be greater than endStation!";
myHandler.sendMessage(msg);
Log.d(TAG, "Please enter a valid station! startStation must be greater than endStation!");
} else {
return true;
}
return false;
}
Handler myHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch(msg.what) {
case 0:
Toast.makeText(getApplicationContext(), msg.obj.toString(), Toast.LENGTH_LONG).show();
break;
}
}
};
public boolean BuyTicket(int number, String departureStation, String terminus) {
//Log.d(TAG, "BuyTicket");
int intPeoArr = number;
int peoplenum = 0;
int seat = 0;
int myArray = 0;
int startStation = 0;
int endStation = 0;
int[] peopleArray = new int[number];
int[] seatArray = new int[number];
int[] myArrayArray = new int[number];
int[] strA = new int[number];
int[] strB = new int[number];
Message msg = new Message();
msg.what = 0;
departureStation = checkStation1(departureStation);
terminus = checkStation1(terminus);
if (departureStation == null || terminus == null) {
return false;
}
startStation = checkStation2(departureStation);
endStation = checkStation2(terminus);
if (startStation == 0 || endStation == 0) {
return false;
}
/* buy */
if (currentTicketNum > TICKETS_MAX) {
currentTicketNum = 0;
}
//Log.d(TAG, " currentTicketNum:" + currentTicketNum);
while(intPeoArr > 0){
peopleArray[intPeoArr-1] = 0;
seatArray[intPeoArr-1] = 0;
myArrayArray[intPeoArr-1] = 0;
strA[intPeoArr-1] = 0;
strB[intPeoArr-1] = 0;
intPeoArr--;
}
for (peoplenum = 0; peoplenum < number; peoplenum++) {
for(seat = 0; seat < SEARS_MAX; seat++) {
for(myArray = 0; myArray < STATION_ONE_TRAIN_MAX; myArray++){
if ( startArray[seat][myArray][1] == 0) {
/*
startArray[seat][myArray][0]= startStation;
startArray[seat][myArray][1]= endStation;
*/
currentTicketNum++;
peopleArray[peoplenum] = 1;
seatArray[intPeoArr] = seat;
myArrayArray[intPeoArr] = myArray;
strA[intPeoArr] = startStation;
strB[intPeoArr] = endStation;
break;
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
毕业设计是高等教育阶段学生在完成学业前所进行的一项重要学术任务,旨在检验学生通过学习所获得的知识、技能以及对特定领域的深刻理解能力。这项任务通常要求学生运用所学专业知识,通过独立研究和创新,完成一个实际问题的解决方案或者开展一项有价值的项目。 首先,毕业设计的选择通常由学生根据个人兴趣、专业方向以及实际需求来确定。学生需要在导师的指导下明确研究目标、问题陈述,确立研究的范围和深度。毕业设计可以包括文献综述、需求分析、方案设计、实施与测试等多个阶段,以确保整个过程的科学性和系统性。 其次,毕业设计的完成通常需要学生具备一定的独立思考和解决问题的能力。在研究过程中,学生可能需要采用各种研究方法,如实验、调查、案例分析等,以获取必要的数据和信息。通过这些活动,学生能够培养扎实的专业技能,提升解决实际问题的实际能力。 第三,毕业设计的撰写是整个过程的重要组成部分。学生需要将研究过程、方法、结果以及结论等详细记录在毕业论文中,以展示其研究的全貌和成果。同时,撰写毕业设计还有助于提高学生的学术写作水平,培养清晰、逻辑的表达能力。 最后,毕业设计的评价通常由导师和相关专业人士进行。评价标准包括研究的创新性、实用性、方法的科学性以及论文的质量等方面。学生在毕业设计中获得的成绩也将直接影响其最终的学业成绩和学位授予。 总的来说,毕业设计是高等教育中的一项重要环节,通过此过程,学生不仅能够巩固所学知识,还能培养独立思考和解决问题的能力,为将来的职业发展奠定坚实的基础。
资源推荐
资源详情
资源评论
收起资源包目录
火车票售票系统.zip (30个子文件)
ABT-code
.gitattributes 378B
java
com
douglas
ticketmanager
writeToFile.java 679B
DouglasService.java 11KB
ClientQueue.java 3KB
TicketStructure.java 447B
BuyTicketTestView.java 5KB
res
mipmap-xxhdpi
ic_launcher.png 8KB
mipmap-hdpi
ic_launcher.png 3KB
drawable-mdpi
station2.jpg 47KB
station1.jpg 47KB
people.jpg 6KB
icon.png 3KB
mipmap-mdpi
ic_launcher.png 2KB
mipmap-xxxhdpi
ic_launcher.png 10KB
drawable-ldpi
station2.jpg 47KB
station1.jpg 47KB
people.jpg 6KB
icon.png 2KB
mipmap-xhdpi
ic_launcher.png 5KB
values
colors.xml 208B
strings.xml 371B
styles.xml 383B
layout
main.xml 4KB
drawable-hdpi
station2.jpg 47KB
station1.jpg 47KB
people.jpg 6KB
icon.png 4KB
.gitignore 649B
aidl
com
dewav
ticket
ITicketManager.aidl 121B
AndroidManifest.xml 1KB
共 30 条
- 1
资源评论
普通的一个普通猿
- 粉丝: 1462
- 资源: 1761
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功