买票java源代码,基于java的火车票售票系统
想用java制作一个自动买火车票的软件,请问怎么实现网页上按钮的点击?
google上有个开源项目组 go_home你可以参考一下
惠山ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
大概的思路是,填写用户名密码,发送到12306执行登陆的地址,然后接受返回的信息,包括cookie(包含sessionID),
然后在模拟网站需要的表单内容填充request发送到“查询”功能对应的地址,然后解析返回的内容
大概就是这样,具体的源代码可以去go_home获取,不过不知道是不是还兼容现在的12306
高分求两个简单的JAVA设计源代码
上面 wuzhikun12同学写的不错,但我想还不能运行,并且还不太完善。我给个能运行的:(注意:文件名为:Test.java)
//要实现对象间的比较,就必须实现Comparable接口,它里面有个compareTo方法
//Comparable最好使用泛型,这样,无论是速度还是代码量都会减少
@SuppressWarnings("unchecked")
class Student implements ComparableStudent{
private String studentNo; //学号
private String studentName; //姓名
private double englishScore; //英语成绩
private double computerScore; //计算机成绩
private double mathScore; //数学成绩
private double totalScore; //总成绩
//空构造函数
public Student() {}
//构造函数
public Student(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
this.studentNo = studentNo;
this.studentName = studentName;
this.englishScore = englishSocre;
this.computerScore = computerScore;
this.mathScore = mathScore;
}
//计算总成绩
public double sum() {
this.totalScore = englishScore+computerScore+mathScore;
return totalScore;
}
//计算评测成绩
public double testScore() {
return sum()/3;
}
//实现compareTO方法
@Override
public int compareTo(Student student) {
double studentTotal = student.getTotalScore();
return totalScore==studentTotal?0:(totalScorestudentTotal?1:-1);
}
//重写toString方法
public String toString(){
return "学号:"+this.getStudentNo()+" 姓名:"+this.getStudentName()+" 英语成绩:"+this.getEnglishScore()+" 数学成绩:"+this.getMathScore()+" 计算机成绩:"+this.getComputerScore()+" 总成绩:"+this.getTotalScore();
}
//重写equals方法
public boolean equals(Object obj) {
if(obj == null){
return false;
}
if(!(obj instanceof Student)){
return false;
}
Student student = (Student)obj;
if(this.studentNo.equals(student.getStudentName())) { //照现实来说,比较是不是同一个学生,应该只是看他的学号是不是相同
return true;
} else {
return false;
}
}
/*以下为get和set方法,我个人认为,totalScore的set的方法没必要要,因为它是由其它成绩计算出来的
在set方法中,没设置一次值,调用一次sum方法,即重新计算总成绩
*/
public String getStudentNo() {
return studentNo;
}
public void setStudentNo(String studentNo) {
this.studentNo = studentNo;
sum();
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
sum();
}
public double getEnglishScore() {
return englishScore;
}
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
sum();
}
public double getComputerScore() {
return computerScore;
}
public void setComputerScore(double computerScore) {
this.computerScore = computerScore;
sum();
}
public double getMathScore() {
return mathScore;
}
public void setMathScore(double mathScore) {
this.mathScore = mathScore;
sum();
}
public double getTotalScore() {
return totalScore;
}
}
//Student子类学习委员类的实现
class StudentXW extends Student {
//重写父类Student的testScore()方法
@Override
public double testScore() {
return sum()/3+3;
}
public StudentXW() {}
//StudentXW的构造函数
public StudentXW(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
}
}
//Student子类班长类的实现
class StudentBZ extends Student {
//重写父类Student的testScore()方法
@Override
public double testScore() {
return sum()/3+5;
}
public StudentBZ() {}
//StudentXW的构造函数
public StudentBZ(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {
super(studentNo,studentName,englishSocre,computerScore,mathScore);
}
}
//测试类
public class Test {
public static void main(String[] args) {
//生成若干个student类、StudentXW类、StudentBZ类
Student student1 = new Student("s001","张三",70.5,50,88.5);
Student student2 = new Student("s002","李四",88,65,88.5);
Student student3 = new Student("s003","王五",67,77,90);
StudentXW student4 = new StudentXW("s004","李六",99,88,99.5);
StudentBZ student5 = new StudentBZ("s005","朱漆",56,65.6,43.5);
Student[] students = {student1,student2,student3,student4,student5};
for(int i = 0 ; istudents.length; i++){
double avgScore = students[i].testScore();
System.out.println(students[i].getStudentName()+"学生的评测成绩为:"+ avgScore+"分");
}
}
}
运行结果为:
张三学生的评测成绩为:69.66666666666667分
李四学生的评测成绩为:80.5分
王五学生的评测成绩为:78.0分
李六学生的评测成绩为:98.5分
朱漆学生的评测成绩为:60.03333333333333分
java多线程的卖票问题
首先,定义的锁(lock)不对,必须是同一个锁,像你这样用this,new多少个MyThread就有多少个锁,违反了线程的同步机制;
其次,你如果想要呈现多线程的竞争,不可以在run方法里让一个线程一直运行而不释放锁,应该使用wait()/notify();
以下我稍微修改下,会形成两个线程交替执行的情形:
public class ThreadTest {
public static Object obj = new Object();
public static int number = 10;// 用static共享票源,不知道可以不,按理说是可以的
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread my = new MyThread();
MyThread my2 = new MyThread();
Thread t1 = new Thread(my2, "2号窗口");
Thread t2 = new Thread(my, "1号窗口");
t1.start();
t2.start();
}
static class MyThread implements Runnable {
public void run() {
while (true)
synchronized (obj) {
if (number 0) {
System.out.println(Thread.currentThread().getName()
+ "正在卖票," + "还剩" + number + "张票");
number--;
obj.notifyAll();
try {
obj.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else
break;
}
}
}
}
用JAVA程序如何获得火车票信息
java 有个HttpClient,可以去抓取别的网页,然后你可以对抓取的字符串进行切割,拆分等操作就能拿到火车的车次信息了!
分享题目:买票java源代码,基于java的火车票售票系统
当前地址:http://scyanting.com/article/hesshh.html