qq_时光老佡_04298173
2016-11-28 17:20
package com.imocc;
import java.util.*;
public abstract class Shape {
public abstract void Zc();
public abstract void Mj();
public class Rectangle extends Shape {
int c,k;
public Rectangle(int c,int k){
this.c=c;
this.k=k;
}
public void Zc() {
// TODO Auto-generated method stub
double Zc=2*(c+k);
System.out.println("长方形的周常为:"+Zc);
}
public void Mj() {
// TODO Auto-generated method stub
double Mj=c*k;
System.out.println("长方形的面积:"+Mj);
}
}
public class Circle extends Shape {
int r;
public Circle(int r){
this.r=r;
}
public void Zc() {
// TODO Auto-generated method stub
double Zc=r*2*3.14;
System.out.println("圆的周常为:"+Zc);
}
public void Mj() {
// TODO Auto-generated method stub
double Mj = r * r * 3.14;
System.out.println("圆形的面积为:" + Mj);
}
}
public void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入圆的半径");
Scanner input = new Scanner(System.in);
int r = input.nextInt();
Shape z= new Circle(r);
z.Zc();
z.Mj();
System.out.println("请输入长方形的长和宽");
Scanner input1 = new Scanner(System.in);
int a = input1.nextInt();
Scanner input2 = new Scanner(System.in);
int b = input2.nextInt();
Shape z1=new Rectangle(a,b);
z1.Zc();
z1.Mj();
}
}
package tuxing; public abstract class Shaper { public abstract void area(); public abstract void perimeter(); } package tuxing; public class Rectangle extends Shaper { float chang,kuan; public void set(float chang,float kuan){ this.chang=chang; this.kuan=kuan; } public float get(){ return chang*kuan; } public float get2(){ return (chang+kuan)*2; } @Override public void area() { // TODO Auto-generated method stub Rectangle a=new Rectangle(); a.set(10.0f,20.0f); System.out.println("矩形的面积是:"+a.get()); } @Override public void perimeter() { // TODO Auto-generated method stub Rectangle b=new Rectangle(); b.set(10.0f,20.0f); System.out.println("矩形的周长是:"+b.get2()); } } package tuxing; public class Circle extends Shaper { float banjing; public void set(float banjing){ this.banjing=banjing; } public float get(){ return banjing*banjing*3.14f; } public float get2(){ return banjing*6.28f; } @Override public void area() { // TODO Auto-generated method stub Circle a=new Circle(); a.set(10.0f); System.out.println("圆形的面积是:"+a.get()); } @Override public void perimeter() { // TODO Auto-generated method stub Circle a=new Circle(); a.set(10.0f); System.out.println("圆形的周长是:"+a.get2()); } } package tuxing; public class Initial { public static void main(String[] args) { // TODO Auto-generated method stub Shaper f=new Rectangle(); f.area(); f.perimeter(); Shaper y=new Circle(); y.area(); y.perimeter(); } }
放这么多代码,想表达什么?
Java入门第二季 升级版
530560 学习 · 6091 问题
相似问题