java有什么面相思想!Java作業 面相抽象原則 在一個列表中,放一個圓形對象,2個矩形對象,和3個三角形對象,并循環輸

java面相程序的題目
自己照著敲進去啊 。
Java作業 面相抽象原則 在一個列表中,放一個圓形對象,2個矩形對象,和3個三角形對象,并循環輸
【java有什么面相思想!Java作業 面相抽象原則 在一個列表中,放一個圓形對象,2個矩形對象,和3個三角形對象,并循環輸】import java.util.*;
public class RecTest {
public static void main(String[] args) {
ArrayList ag=new ArrayList<>();//集合列表!
ag.add(new Cir(5,"圓形1"));
ag.add(new Re(5,8,"矩形1"));
ag.add(new Re(4,10,"矩形2"));
ag.add(new Tr(3,12,"三1"));
ag.add(new Tr(12,5,"三角形2"));
ag.add(new Tr(11,5,"三角形3"));
for(ListIterator lt=ag.listIterator();lt.hasNext();) {
lt.next().area();
}
}
}
abstract class Geometry implements Comparable{
//默認公共屬性,寬,高!
protected double width,high;
protected String name;
Geometry(){}
Geometry(double width,double high,String name){
this.width=width;
this.high=high;
this.name=name;
}
protected void area() {
System.out.println(name "面積=" (width*high));
}
public int hashCode() {
return (int)(width);
}
public boolean equals(Object obj) {
if(!(obj instanceof Geometry))
return false;
Geometry o=(Geometry)obj;
return this.width==o.width;
}
public int compareTo(Geometry g) {
return Double.compare(this.width, g.width);
}
}//三角形!
class Tr extends Geometry{
Tr(double width,double high,String name){
super(width,high,name);
}
protected void area() {
System.out.println(name "面積=" (width*high/2));
}
}//矩形!
class Re extends Geometry{
Re(double width,double high,String name){
super(width,high,name);
}
}//圓!
class Cir extends Geometry{
Cir(double radius,String name){
super(radius,0,name);
}
public void area() {
System.out.println(name "面積=" (3.1415926*width*width));
}
}
誰有達內java面相對象飛機大戰項目視屏
達內?教什么的
大家學javase用了多久,為什么我自學了一個月才學到面相對象,學完了能找到工作嗎?只會se能干嘛
自學的話,估計很難學會的 。不過如果完全學會學懂的話,工作還是很好找的 。