Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // file hinhtron.java
- class hinhtron extends hinh
- {
- private float radius;
- public hinhtron()
- {
- super();
- System.out.print("Nhap do dai canh hv : ");
- this.radius = inp.nextFloat();
- inp.close();
- }
- public float chuvi()
- {
- return radius*4;
- }
- public float dientich()
- {
- return radius*radius;
- }
- public void show()
- {
- System.out.println("Chu vi hcn : " + chuvi());
- System.out.println("Dien tich hcn : " + dientich());
- }
- }
- //file hv.java
- class hv extends hinh
- {
- private float edge;
- public hv()
- {
- super();
- System.out.print("Nhap do dai canh hv : ");
- this.edge = inp.nextFloat();
- inp.close();
- }
- public float chuvi()
- {
- return edge*4;
- }
- public float dientich()
- {
- return edge*edge;
- }
- public void show()
- {
- System.out.println("Chu vi hcn : " + chuvi());
- System.out.println("Dien tich hcn : " + dientich());
- }
- }
- //file hcn.java
- class hcn extends hinh
- {
- private float width, heigh;
- public hcn()
- {
- super();
- System.out.print("Nhap chieu dai hcn : ");
- this.width = inp.nextFloat();
- System.out.print("Nhap chieu rong hcn : ");
- this.heigh = inp.nextFloat();
- inp.close();
- }
- public float chuvi()
- {
- return (width + heigh)*2;
- }
- public float dientich()
- {
- return width * heigh;
- }
- public void show()
- {
- System.out.println("Chu vi hcn : " + chuvi());
- System.out.println("Dien tich hcn : " + dientich());
- }
- }
- //file hinh.java
- import java.util.Scanner;
- abstract class hinh
- {
- Scanner inp = new Scanner(System.in);
- abstract float chuvi();
- abstract float dientich();
- }
- //file main.java
- class java_hinhphang
- {
- public static void main(String [] agrs)
- {
- hcn cn = new hcn();
- hv v = new hv();
- hinhtron ht = new hinhtron();
- cn.show();
- v.show();
- ht.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment