JAVA lab3 第一题

这篇博客展示了Cat类的定义和测试用例。Cat类包含了猫的属性如名字、毛发类型、尾巴状态、颜色和速度,并提供了相应的方法进行设置和获取。CatTest类用于测试Cat类的功能,包括设置猫的属性并打印,创建不同特性的猫实例,以及模拟猫的睡眠和奔跑行为。

在这里插入图片描述
CatTest类

// package dome;

import java.awt.*;

/**
 * Title : CatTest.java Description: This class contains the test class for Cat.
 * Copyright : Copyright (c) 2006 ‐ 2021
 * 
 * @author Laurissa Tokarchuk
 * @version 1.0
 * @author Paula Fonseca
 * @version 1.4
 */
public class CatTest {
    public static void main(String[] args) {
        Cat myCat = new Cat();
        //第二问(2)
        myCat.setName("Napoleon");
        myCat.setSpeed(300);
        System.out.println(myCat.getName()+myCat.getSpeed());
        // myCat.furType = "short";
        // myCat.setTail(true);
        // myCat.setColour(Color.ORANGE);
        // myCat.speed = 300; // in metres per minute
        
        //第三问(3)
        Cat Temp_cat=new Cat("xiaoming","black", true, Color.ORANGE, 300);
        
        
        //第四问(4)
        Cat cat1=new Cat("Tom","short",true,Color.BLACK,500);
        Cat cat2=new Cat("Moggy","long",false,Color.WHITE,400);
        System.out.println("the"+cat1.getName()+"and"+cat1.getfurType()+"of cat1 and call cat1 to run in a straight line for 10 minutes.");
        System.out.println("the"+cat2.getName()+"and"+cat2.getfurType()+"of cat2 and call cat2 to run in a straight line for 5 minutes.");
        //
        myCat.sleep(5);
        int numMetres = myCat.run(10, true);
        System.out.println("I have run " + numMetres + " metres.");
    }
}

Cat类

// package dome;

import java.awt.*;

import javax.swing.plaf.basic.BasicBorders.SplitPaneBorder;

/**
 * Title : Cat.java Description: This class contains the definition of a cat.
 * Copyright : Copyright (c) 2006‐2021
 * 
 * @author Laurissa Tokarchuk
 * @version 1.0
 * @author Paula Fonseca
 * @version 1.4
 */
public class Cat {
    // Declaration of instance variables.
    private String name, furType;
    private boolean tail;
    private Color colour;
    private int speed;

    /**
     * This is the getters and setters;
     * 
     */
    public Cat(){

    }

     public Cat(String name,String furType, boolean tail,Color colour, int speed){
        this.name = name;
        this.colour=colour;
        this.tail=tail;
        this.speed=speed;
        this.furType=furType;
    }






    // public Cat(String name, String furType, boolean tail, Color colour, int speed) {
    //     this.name = name;
    //     this.furType = furType;
    //     this.tail = tail;
    //     this.colour = colour;
    //     this.speed = speed;
    // }


    /**
     * 
     */
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    /**
     * 
     * @return
    */
    public String getfurType(){
        return furType;
    }

    public void setfurType(String furType){
        this.furType=furType;
    }
    
    //

    public boolean isTail() {
        return tail;
    }

    public void setTail(boolean tail) {
        this.tail = tail;
    }
    
    //
    //
    public Color getColour() {
        return colour;
    }


    public void setColour(Color colour) {
        this.colour = colour;
    }

    //

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed){
        this.speed=speed;
    }

    /**
     * This is the sleep method for the cat. It dictates the number of minutes the
     * cat sleeps.
     * 
     * @param duration The number of minutes to sleep.
     */
    public void sleep(int duration) {
        System.out.println("I am sleeping for " + duration + " minutes.");
    }

    

    /**
     * This method allows the cat to run. The distance (in a straight line) the cat
     * runs is dependent on how long the cat runs and whether or not it is running
     * in a zigzag.
     * 
     * @param duration The number of minutes to run.
     * @param zigzag   Whether to run in a zigzag pattern.
     * @return int Number of metres ran.
     */
    public int run(int duration, boolean zigzag) {
        System.out.println("I am running " + (zigzag ? "in a zigzag" : "straight") + " for " + duration + " minutes.");
        int distanceRun = duration * speed; // assuming speed is metres per minute
        if (zigzag) {
            /*
             * When in zigzag, distance is 1/3 of what it would have been if the cat was
             * going straight.
             */
            return distanceRun / 3;
        } else
            return distanceRun;
    }

  
}
【复现】并_离网风光互补制氢合成氨系统容量-调度优化分析(Python代码实现)内容概要:本文围绕“并_离网风光互补制氢合成氨系统容量-调度优化分析”的主,提供了基于Python代码实现的技术研究与复现方法。通过构建风能、太阳能互补的可再生能源系统模型,结合电解水制氢与合成氨工艺流程,对系统的容量配置与运行调度进行联合优化分析。利用优化算法求解系统在不同运行模式下的最优容量配比和调度策略,兼顾经济性、能效性和稳定性,适用于并网与离网两种场景。文中强调通过代码实践完成系统建模、约束设定、目标函数设计及求解过程,帮助读者掌握综合能源系统优化的核心方法。; 适合人群:具备一定Python编程基础和能源系统背景的研究生、科研人员及工程技术人员,尤其适合从事可再生能源、氢能、综合能源系统优化等相关领域的从业者;; 使用场景及目标:①用于教学与科研中对风光制氢合成氨系统的建模与优化训练;②支撑实际项目中对多能互补系统容量规划与调度策略的设计与验证;③帮助理解优化算法在能源系统中的应用逻辑与实现路径;; 阅读建议:建议读者结合文中提供的Python代码进行逐模块调试与运行,配合文档说明深入理解模型构建细节,重点关注目标函数设计、约束条件设置及求解器调用方式,同时可对比Matlab版本实现以拓宽工具应用视野。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值