zzdx软拙Java实验七

实验七  

接口与包

实验目的

1.理解并初步掌握接口的概念及编写

2.初步掌握包的使用;

实验内容与要求

1.前述实验中为类Triangle、Rectangale、Circle引入了一个共同的父类--GeometricObject类,其实Point和Line也应该是Geometricobject的子类,只不过这样一来GeometricObject类中就不应该再包含求周长和面积的方法了。可以考虑用一个接口来描述这两个方法,让类Triangle、Rectangale、Circle来实现这个接口。

2.写出上述接口并重写前述类以适合新的类设计。与前述的继承体系相比,总结使用接口的好处。

3.将上述每个类放至每个不同的文件中,让它们属于同一个包(比如exercise.graphics) ,从中体会包的好处。

代码实现

1. package Demo3;

public class Circle implements function {
    
    static double PI = 3.14159265;
    private double radius;

    public Circle() {
    }

    public Circle(double radius) {
        this.radius = radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    @Override
    public double area() {//面积
        return PI * radius * radius;
    }

    @Override
    public double perimeter() {//周长
        return 2 * PI * radius;
    }

}
2. package Demo3;

public class Rectangle implements function {

    private double lenth;
    private double width;

    public Rectangle() {
    }

    public Rectangle(double lenth, double width) {
        this.lenth = lenth;
        this.width = width;
    }

    public double getLenth() {
        return lenth;
    }

    public void setLenth(double lenth) {
        this.lenth = lenth;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }


    @Override
    public double area() {
        return lenth * width;
    }

    @Override
    public double perimeter() {
        return (lenth + width) * 2;
    }
}
3. package Demo3;

public class Triangle implements function {

    private double a;//各边边长
    private double b;
    private double c;

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public double getC() {
        return c;
    }

    public void setC(double c) {
        this.c = c;
    }

    public Triangle(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public Triangle() {
    }

    @Override
    public double perimeter() {//周长
        return a + b + c;
    }

    @Override
    public double area() {//海伦公式求面积
        double p = perimeter()/2;
        return Math.sqrt(p * (p-a) * (p-b) * (p-c));
    }
}
4. package Demo3;

public interface function {
    public abstract double area();
    public abstract double perimeter();
}
5. package Demo3;

public class Test1 {
    public static void main(String[] args) {
        // Triangle t = new Triangle(4,3,5);
        // System.out.println(t.area());
        System.out.println("测试开始:");

        Rectangle t1 = new Rectangle(2,5);
        System.out.println("矩形周长是:"+t1.perimeter());
        System.out.println("矩形面积是:"+t1.area());

        Circle t2 = new Circle(2);
        System.out.println("圆周长是:"+t2.perimeter());
        System.out.println("圆面积是:"+t2.area());

        Triangle t3 = new Triangle(3,4,5);
        System.out.println("三角形周长是:"+t3.perimeter());
        System.out.println("三角形面积是:"+t3.area());
    }
}

实验截图

输入数据,98行数据:E:\人员轨迹\zzdx\代码\specific_od_pairs\教学楼到餐厅_OD对.csv 举例: od_pair_id person_id od_sequence point_type longitude latitude arrival_time departure_time stay_duration_minutes cluster_radius_meters points_count nearest_building distance_to_building BuildFunction 1020502_0011 1020502 11 O 113.5298966 34.81832795 2024/7/13 11:43 2024/7/13 11:45 2.56 48.45588611 3 教学楼 0 教学楼 1020502_0011 1020502 11 D 113.5246139 34.81623584 2024/7/13 11:45 2024/7/13 11:45 0.170666667 94.77760852 3 餐厅 0.669514354 餐厅 1020541_0004 1020541 4 O 113.5292869 34.81653191 2024/7/13 11:35 2024/7/13 11:36 0.170666667 113.7011223 3 教学楼 0 教学楼 1020541_0004 1020541 4 D 113.5242134 34.81340986 2024/7/13 11:37 2024/7/13 11:38 0.682666667 5.915388439 3 餐厅 0 餐厅 1047238_0004 1047238 4 O 113.5289307 34.81846194 2024/7/13 11:23 2024/7/13 11:24 1.024 178.7609794 9 教学楼 0.928172544 教学楼 1047238_0004 1047238 4 D 113.523855 34.81365456 2024/7/13 11:27 2024/7/13 11:28 0.768 33.72646953 3 餐厅 0 餐厅 1089317_0001 1089317 1 O 113.5299282 34.81968429 2024/7/13 12:01 2024/7/13 12:01 0.426666667 43.22796233 6 教学楼 0 教学楼 1089317_0001 1089317 1 D 113.5242817 34.81496888 2024/7/13 12:20 2024/7/13 12:20 0.341333333 27.73436408 4 餐厅 0 餐厅 输出路径文件夹:E:\人员轨迹\zzdx\代码\od_trajectory_analysis 编写python代码功能要求: 1、利用前面对话中提到的openrouteservice矩阵API,获得O点和D点的最有路径下的速度和时间,要求获取的是对应OD对之间的数据,不保留矩阵中其他不对应O点和D点间的结果 2、计算时间时,要用O点的arrival_time和D点的departure_time间的时间差。 3、生成完整代码
最新发布
11-21
``` rm(list=ls()) # 清除环境变量 setwd("C:/Rdate") # 设置工作目录 getwd() # 查看当前的工作目录 library(pheatmap) # 加载包 library(ggplot2) # 加载包 library(RColorBrewer) library(circlize) if(!require(paletteer))install.packages("paletteer") if(!require(scico))install.packages('scico') if(!require(nord))install.packages('nord') library(paletteer) data <- read.csv("Q7ZZDX1.csv", header=T,# 数据集第一行为变量名 row.names=1,# 第一列为行名 sep=",") annotation_row = data.frame("Q7ZZDX2.csv" ) row.names(annotation_row) <- rownames(data) head(data) p <- pheatmap(data,scale="row",#按行进行归一化,"col"表示按列,"none"表示不进行归一 #annotation_col = annotation_col, #annotation_row =annotation_row, color = colorRampPalette(c("#3025cc","#7f97e6","#fbf5ff","#f0b998","#d13622"))(100), display_numbers=F, #display_numbers = matrix(ifelse(data > 0, "+", "-"), nrow(data)), # 热图上显示数值 cutree_cols = 1,cutree_rows =1, border_color = "#2b2b2b",#边框颜色 cluster_cols = F, # 去掉横向、纵向聚类T真F假 cluster_rows = T,#_cols横,_rows纵 clustering_distance_rows = "correlation",# 设置聚类的距离类型 clustering_method="mcquitty",# 设置聚类方法 show_rownames = T, #去掉横、纵坐标id show_colnames = T, legend = T,# 添加图例 legend_breaks=c (-2,-1,0,1,2),#设置图例范围 fontsize_cols= 5, # 设置字体大小 treeheight_col = 20, # 分别设置横、纵向聚类树高 treeheight_row = 80, cellwidth = 15,cellheight = 10)# 设置热图方块宽度和高度```Error in read.table(file = file, header = header, sep = sep, quote = quote, : 'row.names'里不能有重复的名字
03-27
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值