三角形の色と三角形の幅と高さのユーザー入力を取得するはずですが、出力を表示することもできません。私はちょうど今学校で抽象クラスについて学んでいるので、任意のヒントやポインタが大いに感謝されるだろう。ありがとうございました。抽象クラスでユーザー入力を返すときのトラブル
三角形クラス:
import java.util.Scanner;
public class Triangle extends GeometricObject {
private double base;
private double height;
private int color;
public Triangle() {
}
public static void main(String[] args) {
System.out.println("Enter a width for triangle:");
double base = Integer.parseInt(input.nextInt());
System.out.println("Enter height for triangle:");
double height = Integer.parseInt(input.nextInt());
}
public Triangle(double base, double height) {
this.base = base;
this.height = height;
this.color = color;
}
public double getBase() {
return base;
}
public void setWidth(double width) {
this.base = base;
}
public double getHeight() {
return height;
}
public int getColor(){
return color;
}
public void setHeight(double height) {
this.height = height;
}
public void setColor(int color){
this.color = color;
}
@Override
public double getArea() {
return 0.5* base * height;
}
@Override
public double getPerimeter() {
return 2 * (base + height);
}
}
ここではGeometricClassです:
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;
}
/** Set a new color */
public void setColor(String color) {
this.color = color;
}
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 "created on " + dateCreated + "\ncolor: " + color +
" and filled: " + filled;
}
/** Abstract method getArea */
public abstract double getArea();
/** Abstract method getPerimeter */
public abstract double getPerimeter();
}