找回密码
 立即注册

微信登录

只需一步,快速开始

QQ登录

只需一步,快速开始

搜索
查看: 428|回复: 0

[教程] aardio实现汽车类和人类类

[复制链接]
  • TA的每日心情
    无聊
    2024-3-3 20:52
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    10

    主题

    5

    回帖

    116

    积分

    版主

    积分
    116
    来自: 英国
    发表于 2024-2-7 23:39:52 | 显示全部楼层 |阅读模式 来自: 英国
    非业余 - aardio 编程语言 - 非官方问答社区
    限时85折!暑假期间,用aardio培训班充实自己!https://mp.weixin.qq.com/s/c4Z8sZPOiMh_OTG2VPOJmA
    Aardio培训大揭秘,轻松上手打造个人项目!https://mp.weixin.qq.com/s/cr47qhp_Cpz0p57lbbPwug
    aardio风行者第二期培训班https://mp.weixin.qq.com/s/uB6XHUDnGSk0JlWuiBE9AA
    本帖最后由 axuanup 于 2024-2-7 23:45 编辑

    [AAuto] 纯文本查看 复制代码
    import console
    //实现汽车类
    class Car {
        ctor(make, model, color, year) {
            this.make = make
            this.model = model
            this.color = color
            this.year = year
        }
    
        startEngine = function() {
            return '汽车引擎启动...'
        }
    
        stopEngine = function() {
            return '汽车引擎关闭...'
        }
    
        drive = function() {
    
            return this.make + this.model + '正在行驶...'
        }
    
        displayDetails = function() {
            return '汽车详细信息: ' + '制造商: ' + this.make + ', 型号: ' + this.model + ', 颜色: ' + this.color + ', 年份: ' + this.year
        }
    }
    
    var myCar = Car('奥迪', 'A4', '黑色', 2020)
    console.log(myCar.startEngine())
    console.log(myCar.drive())
    console.log(myCar.stopEngine())
    console.log(myCar.displayDetails())
    
    //实现人类类
    
    class Human{
        ctor(name, age, gender) { //类构造函数初始化人类的姓名,年龄和性别
            this.name = name
            this.age = age
            this.gender = gender
        }
      
        eat = function() { //一个吃饭的方法
            ..console.log(this.name + "正在吃饭。")
        }
    
        sleep = function() { //一个睡觉的方法
            ..console.log(this.name + "正在睡觉。")
        }
    
        work = function() { //一个工作的方法
           ..console.log(this.name + "正在工作。")
        }
    
        displayHuman = function() { //一个显示人类信息的方法
            ..console.log("姓名: " + this.name + ",年龄:" + this.age + ",性别:" + this.gender)
        }
    }
    
    newHuman = Human("张三", 25, "男")
    newHuman.eat()
    newHuman.sleep()
    newHuman.work()
    newHuman.displayHuman()
    
    
    console.pause(true)


    非业余 - aardio 编程语言 - 非官方问答社区
    限时85折!暑假期间,用aardio培训班充实自己!https://mp.weixin.qq.com/s/c4Z8sZPOiMh_OTG2VPOJmA
    Aardio培训大揭秘,轻松上手打造个人项目!https://mp.weixin.qq.com/s/cr47qhp_Cpz0p57lbbPwug
    aardio风行者第二期培训班https://mp.weixin.qq.com/s/uB6XHUDnGSk0JlWuiBE9AA
    回复

    使用道具 举报

    *滑块验证:
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|非业余 - aardio 编程语言 - 非官方问答社区

    GMT+8, 2024-9-17 03:36 , Processed in 0.118073 second(s), 30 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表