package practice;
public abstract class shape {
public abstract void area();
public abstract void paremeter();
}package practice;
import java.util.Scanner;
public class rectangle extends shape {
@Override
public void area() {
// TODO Auto-generated method stub
Scanner input= new Scanner(System.in);
System.out.println("输入宽:");
float w= input.nextFloat();
System.out.println("输入长:");
float l= input.nextFloat();
System.out.println("长方形面积:"+w*l);
}
@Override
public void paremeter() {
// TODO Auto-generated method stub
Scanner input= new Scanner(System.in);
System.out.println("输入宽:");
float w= input.nextFloat();
System.out.println("输入长:");
float l= input.nextFloat();
System.out.println("长方形周长:"+2*(w+l));
}
}package practice;
import java.util.Scanner;
public class circle extends shape {
@Override
public void area() {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in) ;
System.out.print("输入半径:");
float r=input.nextFloat();
System.out.println("圆面积:"+Math.PI*r*r);
}
@Override
public void paremeter() {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in) ;
System.out.print("输入半径:");
float r=input.nextFloat();
System.out.println("圆周长"+2*Math.PI*r);
}
}package practice;
import java.util.Scanner;
public class Initial {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("请输入图形形状:");
Scanner input= new Scanner(System.in);
String i1= input.next();
if (i1=="圆"){
System.out.println("开始计算圆。。。");
System.out.println("输入面积或周长:");
shape s1=new circle();
String i2= input.next();
if(i2=="面积"){
System.out.print("开始计算面积。。。");
s1.area();
}else{
System.out.print("开始计算周长。。。");
s1.paremeter();
}
}else{
System.out.println("开始计算长方形。。。");
System.out.println("输入面积或周长:");
shape s2=new rectangle();
String i2= input.next();
if(i2=="面积"){
System.out.print("开始计算面积。。。");
s2.area();
}else{
System.out.print("开始计算周长。。。");
s2.paremeter();
}
}
}
}
添加回答
举报
0/150
提交
取消