由于题目中没有明确要求程序实现什么功能,因此以下代码仅供参考:

import java.util.ArrayList;

public class Lantern {

    private String shape;
    private ArrayList<String> colors;

    public Lantern(String shape, ArrayList<String> colors) {
        this.shape = shape;
        this.colors = colors;
    }

    public String getShape() {
        return shape;
    }

    public ArrayList<String> getColors() {
        return colors;
    }

    public static void main(String[] args) {
        ArrayList<String> colors = new ArrayList<String>();
        colors.add("red");
        colors.add("yellow");
        colors.add("green");
        colors.add("blue");

        Lantern rabbitLantern = new Lantern("rabbit", colors);
        Lantern flowerLantern = new Lantern("flower", colors);

        System.out.println("Rabbit lantern shape: " + rabbitLantern.getShape());
        System.out.println("Rabbit lantern colors: " + rabbitLantern.getColors());
        System.out.println("Flower lantern shape: " + flowerLantern.getShape());
        System.out.println("Flower lantern colors: " + flowerLantern.getColors());
    }
}

以上代码定义了一个 Lantern 类,其中包含了灯笼的形状和颜色。在 main 方法中创建了两个 Lantern 对象,一个是兔子形状的花灯,一个是花朵形状的花灯。最后输出两个灯笼的形状和颜色。

写一段关于-兔子-花灯-元宵的-java-代码

原文地址: https://www.cveoy.top/t/topic/jb3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录