20200730 千锤百炼软工人第二十五天
今天完成了一个程序
这个程序第一次感受了内部类的运用
以及它的逻辑重要性
其次还有学习了接口的一部分内容
在此附上代码和运行截图
package a20200730;
public class Point {
private double x;
private double y;
Point(double x,double y){
this.x=x;
this.y=y;
System.out.print("Point Constructor run\n");
}
Point(){
this.x=0;
this.y=0;
System.out.print("Point Constructor run\n");
}
Point(Point p){
this.x=p.x;
this.y=p.y;
System.out.print("Point CopyConstructor run\n");
}
public void finalize() {
System.out.print("Point Destructor run\n");
}
public void setX(double x) {
this.x=x;
}
public void setY(double y) {
this.y=y;
}
public void setX() {
this.x=0;
}
public void setY() {
this.y=0;
}
public double getX() {
return this.x;
}
public double getY() {
return this.y;
}
public void show() {
System.out.print("("+this.x+","+this.y+")");
}
public double area() {
return 0;
}
}
圆类
package a20200730;
public class Circle extends Point {
public static double PI=3.14159;
private double radius;
Circle(double x,double y,double r){
this.setX(x);
this.setY(y);
this.radius=r;
System.out.print("Circle Constructor run\n");
}
Circle(Circle c){
this.setX(c.getX());
this.setY(c.getY());
this.radius=c.radius;
System.out.print("Circle CopyConstructor run\n");
}
Circle(){
this.setX(0);
this.setY(0);
this.radius=0;
System.out.print("Circle Constructor run\n");
}
public void finalize() {
System.out.print("Circle Destructor run\n");
}
public void setRadius(double r) {
this.radius=r;
}
public double getRadius() {
return this.radius;
}
public double circumference() {
return this.radius*2*PI;
}
public double area() {
return this.radius*this.radius*PI;
}
public void show() {
System.out.print("("+this.getX()+","+this.getY()+"),Radius="+this.radius);
}
}
球类
private class point extends Point{
}
private class circle extends Circle{
}
private point p = new point();
private circle c = new circle();
Sphere(double x,double y,double r){
c.setX(x);
c.setY(y);
c.setRadius(r);
System.out.print("Sphere Destructor run\n");
}
Sphere(Sphere a){
this.c.setX(a.c.getX());
this.c.setY(a.c.getY());
this.c.setRadius(a.c.getRadius());
System.out.print("Sphere CopyDestructor run\n");
}
Sphere(){
c.setX();
c.setY();
c.setRadius(0);
System.out.print("Sphere Constructor run\n");
}
public void finalize() {
System.out.print("Sphere Destructor run\n");
}
public double volume() {
return c.getRadius()*c.getRadius()*c.getRadius()*c.PI*4/3;
}
public double circumference() {
return c.circumference();
}
public double area() {
return c.getRadius()*c.getRadius()*c.PI*4;
}
public double area(Sphere s) {
return s.c.area();
}
public void setRadius(double r) {
this.c.setRadius(r);
}
public void show() {
this.c.show();
}
}
package a20200730;
import java.util.Scanner;
public static void main(String[] arg) {
double r;
Scanner r1 = new Scanner(System.in);
r = r1.nextDouble();
Sphere s1 = new Sphere(1,2,4);
Sphere s2 = new Sphere(s1);
s1.show();
System.out.print("\nArea="+s1.area()+"\nVolume="+s1.volume()+"\n");
s2.setRadius(r);
s2.show();
System.out.print("\nArea="+s2.area(s2)+"\nCircumference"+s2.circumference()+"\n");
s1 = null;
s2=null;
System.gc();
}
}

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」