求一个用java编写来计算机飞机航线里程的小程序,比如北京到贵阳

求一个用java编写来计算机飞机航线里程的小程序,比如北京到贵阳,第1张

public class HanxianTest {

static ArrayList<MyPoint>hanxian

public HanxianTest() {

hanxian = new Hangxian()

hanxian.add(new MyPoint(105.36, 236.77))// 添加城市坐标

hanxian.add(new MyPoint(245.62, 356.94))// 添加城市坐标

hanxian.add(new MyPoint(101.36, 206.77))// 添加城市坐标

}

public static void main(String[] args) {

HanxianTest hashMapTest = new HanxianTest()

System.out.println("这条航线的距离为---------"+((Hangxian) hanxian).GetDis())

}

private static double rad(double d) {

return d * Math.PI / 180.0

}

public static double GetDistance(double lat1, double lng1, double lat2,

double lng2) {

double EARTH_RADIUS = 6378.137// 地球半径

double radLat1 = rad(lat1)

double radLat2 = rad(lat2)

double a = radLat1 - radLat2

double b = rad(lng1) - rad(lng2)

double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)

+ Math.cos(radLat1) * Math.cos(radLat2)

* Math.pow(Math.sin(b / 2), 2)))

s = s * EARTH_RADIUS

s = Math.round(s * 10000) / 10000

return s

}

class Hangxian extends ArrayList<MyPoint>{

/**

*/

private static final long serialVersionUID = 1L

public double GetDis() {

BigDecimal distance = new BigDecimal(0)

for (int i = 0i <this.size() - 1i++) {

double tmp = GetDistance(get(i).getX(), get(i).getY(),

get(i + 1).getX(), get(i + 1).getY())

distance = distance.add(BigDecimal.valueOf(tmp))

}

return distance.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue()

}

}

class MyPoint {

private double x

private double y

public MyPoint(double x, double y) {

this.x = x

this.y = y

}

public double getX() {

return x

}

public void setX(double x) {

this.x = x

}

public double getY() {

return y

}

public void setY(double y) {

this.y = y

}

}

}

他们的接口一般通过两个方式

第一:航班有官网,可以查询航班信息

第二:航空公司有专门的接口,提供给携程

第二种你个人不急不行,只能第一种

就是HTTPCLIENT模拟提交你的查询信息,然后把返回结果取出来展示

public class Ticket {

private int month

private int classLevel//1: 头等舱, 2: 经济舱

private int price

private int basePrice = 5000//原价

public Ticket(int month, int classLevel) {

this.month = month

this.classLevel = classLevel

}

public void showMeThePrice() {

//旺季月份: 4-10

if ((month >= 4) &&(month <= 10)) {

if (classLevel == 1) {

price = basePrice * 0.9

System.out.println("Month: " + month + "Class: " + classLevel + "Price: " + price)

} else if (classLevel == 2) {

price = basePrice * 0.8

System.out.println("Month: " + month + "Class: " + classLevel + "Price: " + price)

}

}

// 淡季月份: 1,2,3,11,12

if ((month >= 1) &&(month <= 3) || month = 11 || month = 12) {

if (classLevel == 1) {

price = basePrice * 0.5

System.out.println("Month: " + month + "Class: " + classLevel + "Price: " + price)

} else if (classLevel == 2) {

price = basePrice * 0.4

System.out.println("Month: " + month + "Class: " + classLevel + "Price: " + price)

}

}

}

}

测试类:

public class Test {

Ticket myTicket = new Ticket(4, 1)//例如:四月,头等舱

myTicket.showMeThePrice()//输出显示价格

...

}

以上代码全部手打,因为公司没有安装jdk,所以无法测试,你自己调试吧。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/8011218.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存