Reset author name to chosen name ✨
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.lab4_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Circle extends GeometricObject {
|
||||
private double radius;
|
||||
|
||||
public Circle() {
|
||||
}
|
||||
|
||||
public Circle(double radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
/** Return radius */
|
||||
public double getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
/** Set a new radius */
|
||||
public void setRadius(double radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
@Override /** Return area */
|
||||
public double getArea() {
|
||||
return radius * radius * Math.PI;
|
||||
}
|
||||
|
||||
/** Return diameter */
|
||||
public double getDiameter() {
|
||||
return 2 * radius;
|
||||
}
|
||||
|
||||
@Override /** Return perimeter */
|
||||
public double getPerimeter() {
|
||||
return 2 * radius * Math.PI;
|
||||
}
|
||||
|
||||
/* Print the circle info */
|
||||
public void printCircle() {
|
||||
System.out.println("The circle is created " + getDateCreated() +
|
||||
" and the radius is " + radius);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.lab4_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public abstract class GeometricObject {
|
||||
private String color = "white";
|
||||
private boolean filled;
|
||||
private java.util.Date dateCreated;
|
||||
|
||||
/** Construct a default geometric object */
|
||||
protected GeometricObject() {
|
||||
dateCreated = new java.util.Date();
|
||||
}
|
||||
|
||||
/** Construct a geometric object with color and filled value */
|
||||
protected GeometricObject(String color, boolean filled) {
|
||||
dateCreated = new java.util.Date();
|
||||
this.color = color;
|
||||
this.filled = filled;
|
||||
}
|
||||
|
||||
/** Return color */
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/** Set a new color */
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/** Return filled. Since filled is boolean,
|
||||
* the get method is named isFilled */
|
||||
public boolean isFilled() {
|
||||
return filled;
|
||||
}
|
||||
|
||||
/** Set a new filled */
|
||||
public void setFilled(boolean filled) {
|
||||
this.filled = filled;
|
||||
}
|
||||
|
||||
/** Get dateCreated */
|
||||
public java.util.Date getDateCreated() {
|
||||
return dateCreated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "GeometricObject{" + "color=" + color + ", filled=" + filled + ", dateCreated=" + dateCreated + '}';
|
||||
}
|
||||
|
||||
/** Abstract method getArea */
|
||||
public abstract double getArea();
|
||||
|
||||
/** Abstract method getPerimeter */
|
||||
public abstract double getPerimeter();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package com.chloefontenot.lab4_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Lab4_ChloeFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.lab4_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Rectangle extends GeometricObject {
|
||||
private double width;
|
||||
private double height;
|
||||
|
||||
public Rectangle() {
|
||||
}
|
||||
|
||||
public Rectangle(double width, double height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/** Return width */
|
||||
public double getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
/** Set a new width */
|
||||
public void setWidth(double width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
/** Return height */
|
||||
public double getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
/** Set a new height */
|
||||
public void setHeight(double height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override /** Return area */
|
||||
public double getArea() {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
@Override /** Return perimeter */
|
||||
public double getPerimeter() {
|
||||
return 2 * (width + height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.lab4_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class TestCircleRectangle {
|
||||
public static void main(String[] args) {
|
||||
Circle circle = new Circle(1);
|
||||
System.out.println(circle);
|
||||
/*
|
||||
CircleFromSimpleGeometricObject circle =
|
||||
new CircleFromSimpleGeometricObject(1);
|
||||
System.out.println("A circle " + circle.toString());
|
||||
System.out.println("The color is " + circle.getColor());
|
||||
System.out.println("The radius is " + circle.getRadius());
|
||||
System.out.println("The area is " + circle.getArea());
|
||||
System.out.println("The diameter is " + circle.getDiameter());
|
||||
|
||||
RectangleFromSimpleGeometricObject rectangle =
|
||||
new RectangleFromSimpleGeometricObject(2, 4);
|
||||
System.out.println("\nA rectangle " + rectangle.toString());
|
||||
System.out.println("The area is " + rectangle.getArea());
|
||||
System.out.println("The perimeter is " +
|
||||
rectangle.getPerimeter());
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Apple extends Fruit {
|
||||
|
||||
}
|
||||
|
||||
class Fruit {
|
||||
public Fruit () {}
|
||||
public Fruit(String name) {
|
||||
System.out.println("Fruit's constructior is invoked.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user