This commit is contained in:
ldy
2026-03-01 23:18:55 -05:00
commit 67f753a5d1
3087 changed files with 218259 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Question3</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,26 @@
public class Circle extends Shape{
//instance variable
private double radius;
//constructor
public Circle(double x, double y, double radius) {
super(x, y);
this.radius = radius;
}
//method
public double area() {
return Math.PI * this.radius * this.radius;
}
//test
public static void testCircle() {
Circle c = new Circle(1.2, 3.4, 4.0);
// getX and getY are inherited from Shape.
// area comes from Circle itself.
System.out.println(c.getX() == 1.2);
System.out.println(c.getY() == 3.4);
System.out.println(c.area() == Math.PI * 16.0);
}
}

View File

@@ -0,0 +1,20 @@
public class Dot extends Shape {
//constructor
public Dot(double x, double y) {
super(x, y);
}
//method
public double area() {return 0.0;} //a dot has no geo-area
//test
public static void testDot() {
Dot d = new Dot(1.2, 3.4);
// getX and getY are inherited from Shape.
// area comes from Dot itself.
System.out.println(d.getX() == 1.2);
System.out.println(d.getY() == 3.4);
System.out.println(d.area() == 0.0);
}
}

View File

@@ -0,0 +1,31 @@
public class Shape {
//instance variables
private double x;
private double y;
//constructor
public Shape(double x, double y) {
this.x = x;
this.y = y;
}
//methods
public double getX() {return this.x;}
public double getY() {return this.y;}
public double area() {
System.out.println("An unknown shape has an unknown area!");
return -1.0;
}
//test
public static void testShape() {
Shape s = new Shape(1.2, 3.4);
System.out.println(s.getX() == 1.2);
System.out.println(s.getY() == 3.4);
System.out.println(s.area() == -1.0); // Will print an error message too.
}
}

View File

@@ -0,0 +1,10 @@
public class Start {
public static void main(String[] args) {
Shape.testShape();
Circle.testCircle();
Dot.testDot();
}
}