اشکال هندسی
سه شنبه, ۱۳ آبان ۱۳۹۹، ۱۱:۵۶ ب.ظ
مشکل: وقتی double 5 بود 5.0 چاپ می کردم!
\\Shape.java
package ir.javacup.paint;
import java.util.*;
public class Shape {
Color color;
Pattern pattern;
public Shape(Color c, Pattern p) {
this.color = c;
this.pattern = p;
}
protected String tell()
{
return String.format("[color:%s, pattern:%s, ",this.color,this.pattern);
}
protected boolean comp(Shape a,Shape b)
{
if((a.color)==(b.color) && a.pattern==b.pattern)
return true;
return false;
}
}
enum Color {
BLUE, GREEN, RED
}
enum Pattern {
DOTTED, STRIPED, ZIGZAG
}
\\circle
package ir.javacup.paint;
import java.text.DecimalFormat;
public class Circle extends Shape {
Double radius;
public Circle(Color c, Pattern p, double r) {
super(c, p);
this.radius = r;
}
@Override
public String toString()
{
DecimalFormat format = new DecimalFormat("0.#");
// String a=String.valueOf(b);
return "Circle"+this.tell()+"radius:"+format.format(radius)+"]";
}
public boolean equals(Circle obj)
{
if(obj==null || this==null) return false;
System.out.println("hey here first radius:");
// System.out.println(Double.valueOf(this.radius));
//System.out.println("sec radius:");
//System.out.println(Double.v.valueOf(obj.radius));
System.out.println();
if((this.radius).doubleValue()==(obj.radius).doubleValue() && comp(obj,this))
return true;
return false;
}
}
package ir.javacup.paint;
public class Square extends Shape {
Integer length;
public Square(Color c, Pattern p, int length) {
super(c, p);
this.length = length; // autoboxing
}
@Override
public String toString()
{
return "Square"+this.tell()+"length:"+length.toString()+"]";
}
public boolean equals(Square obj)
{
if(obj==null || this==null) return false;
if(this.length==obj.length && comp(obj,this))
return true;
return false;
}
}
۹۹/۰۸/۱۳