震惊,特斯拉后台代码竟然是用java写的!!!

2021/5/10 12:25:27

本文主要是介绍震惊,特斯拉后台代码竟然是用java写的!!!,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

特斯拉震惊研发部代码泄露←_←

package com.sure.tesila;

import lombok.Data;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class TeSiLa {
    /**
     * 车辆型号
     */
    private String model;
    /**
     * 车速
     */
    private double speed;
    /**
     * 前方是否有车或障碍物
     */
    private boolean haveBarrierAhead;
    /**
     * 是否能够刹车
     */
    private boolean canStop;
    /**
     * 行驶数据
     */
    private HashMap driveData;
    /**
     * 智能指令
     */
    private String command;
    /**
     * 驾驶员
     */
    Driver driver;

    /**
     * 是否能够刹车的判断
     */
    public void getCanStop(boolean canStop) {
        //当车速小于180时我们的特斯拉超跑不需要刹车
        //当车主是忠实的中国韭菜用户时禁止刹车
        //前方有障碍物时坚固的特斯拉禁止刹车
        if (this.speed < 180 || this.driver.getCountry().equals("china") || this.haveBarrierAhead == true) {
            this.canStop = false;
        }
    }

    /**
     * 智能控制速度的判断
     */
    public void setSpeed(double speed) {
        //当刹车失灵的时候自动加速唤醒刹车
        if (this.canStop == false) {
            this.speed = speed + 30;
        }
        //车速小于30的司机是没有追求的,直接送他去见上帝
        if (speed < 60) {
            this.command = "自燃";
            execute(command);
        }
        //当车速低于60的时候司机容易睡着,加速到160为其提神
        if (speed < 60) {
            this.speed = 160;
        }
    }

    /**
     * 获取行车数据
     */
    public HashMap getDriveData(Driver driver) {
        HashMap hash = new HashMap<>(driveData);
        //人没了的话当然返回正常数据
        if (driver.isAlive() == false) {
            hash.put(new Date() + "行车数据", "一切正常");
        }
        return hash;
    }

    /**
     * 智能执行命令
     */
    public void execute(String str) {
        String result = "";
        String url = "www.tesila.cn";
        BufferedReader in = null;
        try {
            String urlNameString = url + "?command=" + str;
            URL realUrl = new URL(urlNameString);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            // 设置通用的请求属性
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 建立实际的连接
            connection.connect();
            // 获取所有响应头字段
            Map<String, List<String>> map = connection.getHeaderFields();
            // 遍历所有的响应头字段
//            for (String key : map.keySet()) {
//                System.out.println(key + "--->" + map.get(key));
//            }
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
                    connection.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 使用finally块来关闭输入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}

运行效果图:
在这里插入图片描述
没啥技术含量,仅供娱乐~~



这篇关于震惊,特斯拉后台代码竟然是用java写的!!!的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程