By GokiSoft.com| 15:38 16/06/2023|
Java Basic

Java Basic- OOP - Chu vi và diện hình hình tròn & hình chữ nhật BT985

Xây dựng chương trình gồm các chức năng sau
1. Tạo lớp Circle gồm thuộc tính bán kinh và các phương thức sau
- Trả về số PI
- Nhập thông tin bán kính
- Tính chu vi hình tròn - Ko tham sô - trả về chu vi hình tròn đó
- Tính diện tích hình tròn - ko tham số - trả về diện tích hình tròn đó
2. Tạo lớp hình chữ nhật
Gồm 2 thuộc tính chiều dai và chiều rộng
Gồm các phương thức
- Nhập thông tin chiều dài và chiều rộng
- Tính chu vi
Tính diện tích
3. Xây dựng menu chương trình như sau
1. Nhập thông tin hình tròn
2. Tính chu vi hình tròn
3. Tính diện tích hình tròn
4. Nhập thông tin hcn
5. Tính chu vi hcn
6. Tính diện tích hcn
7. Thoát

Liên kết rút gọn:

https://gokisoft.com/985

Bình luận

avatar
Chu Quốc Việt [community,C2010L]
2021-08-03 15:01:31


#Circle.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.exam;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Circle extends GeometricObject {
    double radius;
    double Diameter;
    final float PI=3.14f;
    public Circle() {
    }

    public Circle(double radius) {
        this.radius = radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    public double getDiameter() {
        return Diameter;
    }
    
    
    
    @Override
    double getArea(){
        return radius*radius*PI ;
    }

    @Override
    double getPerimeter() {
        return Diameter*PI;
    }
    @Override
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Radius :");
        radius = scan.nextDouble();
        System.out.println("Diameter :");
        Diameter = scan.nextDouble();
    }

    
    
}


#GeometricObject.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.exam;

import java.util.Date;
import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public abstract class GeometricObject {

    String color;
    boolean filled;
    java.util.Date dateCreate;

    public GeometricObject() {
    }

    public GeometricObject(String color, boolean filled, Date dateCreate) {
        this.color = color;
        this.filled = filled;
        this.dateCreate = dateCreate;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public boolean isFilled() {
        return filled;
    }

    public void setFilled(boolean filled) {
        this.filled = filled;
    }

    public Date getDateCreate() {
        return dateCreate;
    }

    public void setDateCreate(Date dateCreate) {
        this.dateCreate = dateCreate;
    }

      abstract double getArea() ;
      abstract double getPerimeter();
     public void input(){
         Scanner scan = new Scanner(System.in);
         System.out.println("Nhap Color");
         color = scan.nextLine();
         System.out.println("Nhap Filled");
         filled = scan.nextBoolean();

     }
     

    void input(Scanner in) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}


#Rectangle.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.exam;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Rectangle extends GeometricObject{
    double width,height;

    public Rectangle() {
    }

    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }
    
    @Override
    double getArea() {
        return width*height;
    }

    @Override
    double getPerimeter() {
        return 2*(width+height);
    }
    @Override
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Width");
        width = scan.nextDouble();
        System.out.println("Height");
        height = scan.nextDouble();
    }

   
    
}


#Tesst.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.exam;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Tesst {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Circle circle = new Circle();
        Rectangle rectangle = new Rectangle();
        Scanner scan = new Scanner(System.in);
        int choice;
        do {
            showmenu();
            choice = scan.nextInt();
            switch (choice) {
                case 1:
                    circle.input();
                    break;
                case 2:
                    System.out.println("Chu Vi" + circle.getArea());
                    break;
                case 3:
                    System.out.println("Dien tich" + circle.getPerimeter());
                    break;
                case 4:
                    rectangle.input();
                    break;
                case 5:
                    System.out.println("Chu vi hcn :" + rectangle.getArea());
                    break;
                case 6:
                    System.out.println("dien tich hcn :" + rectangle.getPerimeter());
                    break;
                case 7:
                    System.out.println("Thoat !!!!");
                    break;
                default:
                      System.out.println("Vui Long nhap lai!!");
                            break;
            }

        } while (choice != 7);

    }

    static void showmenu() {
        System.out.println("1: Nhap thong tin hinh tron");
        System.out.println("2: Tinh chu vi hinh tron");
        System.out.println("3: Tinh dien tich hinh tron");
        System.out.println("4: Nhap thong tin hinh chu nhat");
        System.out.println("5: Tinh chu vi hinh chu nhat ");
        System.out.println("6: Tinh dien tich hinh chu nhat");
        System.out.println("7: Thoat");
    }
}


avatar
Võ Như Việt [C2010L]
2021-08-03 14:33:54


#Calcu.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BT985;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Calcu {

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        int choose;
        Circle circle = new Circle();
        Rectangle rectangle = new Rectangle();
        Scanner sc = new Scanner(System.in);
        do {            
            showMenu();
            choose = Integer.parseInt(sc.nextLine());
            
            switch(choose){
                case 1:
                    circle.input();
                    break;
                case 2:
                    circle.Chuvihinhtron();
                    break;
                case 3:
                    circle.Dientichhinhtron();
                    break;
                case 4:
                    rectangle.inputCN();
                    break;
                case 5:
                    rectangle.ChuViHCN();
                    break;
                case 6:
                    rectangle.DienTichHCN();
                    break;
                case 7:
                    System.out.println("Thoat chuong trinh...");
                    break;
                 default:
                     System.out.println("Chon sai!!!");
                     break;
            }
            
        } while (choose !=7 );
    }
    
    static void showMenu(){
        System.out.println("1.Nhap thong tin hinh tron");
        System.out.println("2.Tinh chu vi hinh tron");
        System.out.println("3.Tinh dien tich hinh tron");
        System.out.println("4.Nhap thong tin HCN");
        System.out.println("5.Tinh chu vi hinh HCN");
        System.out.println("6.Tinh dien tich hinh HCN");
        System.out.println("7.thoat");
        System.out.println("Chon: ");
        
    }
}


#Circle.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BT985;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Circle {

    double BanKinh;

    public Circle() {
    }

    public double getBanKinh() {
        return BanKinh;
    }

    public void setBanKinh(double BanKinh) {
        this.BanKinh = BanKinh;
    }
    
    public void input(){
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ban kinh: ");
        BanKinh = sc.nextInt();
    }
    
    double Chuvihinhtron(){
        double Chuvihinhtron = BanKinh * 2 * Math.PI;
        System.out.printf("Chu Vi Hinh Tron = %f \n", Chuvihinhtron );
        return Chuvihinhtron;
        
    }
    
    double Dientichhinhtron(){
        double Dientichhinhtron = BanKinh * BanKinh * Math.PI;
         System.out.printf("Dien tich hinh tron = %f \n", Dientichhinhtron );
        return Dientichhinhtron;
    }
    
    
}


#Rectangle.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BT985;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Rectangle {
    double height,width;

    public Rectangle() {
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }
    
    public void inputCN(){
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap chieu dai:");
        height = Double.parseDouble(sc.nextLine());
        System.out.println("Nhap chieu rong:");
        width = Double.parseDouble(sc.nextLine()); 
    }
    
    double ChuViHCN(){
        double ChuViHCN = (width + height)*2;;
         System.out.printf("Chu Vi HCN = %f \n", ChuViHCN );
        return ChuViHCN;
        
    }
    
    double DienTichHCN(){
        double DienTichHCN = width * height;
            System.out.printf("Dien Tich HCN = %f \n", DienTichHCN );
        return DienTichHCN ;
    }
}


avatar
cuonglee [C1907L]
2020-04-02 15:36:10



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package TinhToanHinh;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Main {
    public static void main(String[] args) {
        
        Scanner input = new Scanner(System.in);
       HinhTron htron = new HinhTron();
       HinhChuNhat hcn =new HinhChuNhat();
       
       int choose;
      do{
        show();
        choose = Integer.parseInt(input.nextLine());
          
         switch(choose){
            case 1:
                htron.nhap();
                break;
            case 2:
                htron.ChuVi();
                break;
            case 3:
                htron.DienTich();
                break;
            case 4:
                  hcn.nhap();
                  break;
            case 5:
                hcn.ChuViHcn();
                break;
            case 6:
                hcn.DienTichHcn();
                break;
            case 7:
                System.out.println("Thoat");
                break;
                
                
          
      }
      }while(choose != 7);
       
    }
    public static void show(){
                System.out.println("--------------Menu-------------");
		System.out.println("1. Nhap thong tin hinh tron.");
		System.out.println("2. tinh chu vi hinh tron.");
		System.out.println("3. tinh dien tich hinh tron.");
                System.out.println("4. Nhap thong tin hinh chu nhat.");
		System.out.println("5. tinh chu vi hinh chu nhat.");
		System.out.println("6. tinh dien tich hinh chu nhat.");
                System.out.println("7. Thoat.");
		System.out.println("-------------------------------");
    }

   
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package TinhToanHinh;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class HinhTron {
    float PI = 3.14f;
    float r,cv,dt;
    
    public void nhap(){
        Scanner add = new Scanner(System.in);
        System.out.println("nhap ban kinh");
        r = add.nextFloat();
    }
    public void ChuVi(){
        System.out.println("chu vi cua hinh tron la: ");
        cv =  2*r*PI;
        System.out.println(cv);
    }
    public void DienTich(){
        System.out.println("dien tich cua hinh tron la: ");
        dt = PI * r*r;
        System.out.println(dt);
    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package TinhToanHinh;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class HinhChuNhat {
    int a,b;
    int P,S;
    public void nhap(){
        Scanner add = new Scanner(System.in);
        System.out.println("nhap chieu dai :");
        a = add.nextInt();
        System.out.println("nhap chieu rong :");
        b = add.nextInt();
    }
    public void ChuViHcn(){
        System.out.println("chu vi cua hinh chu nhat la: ");
        P =(a+b)*2;
        System.out.println(P);
    }
    public void DienTichHcn(){
        System.out.println("dien tich cua hinh chu nhat la: ");
        S = a*b;
        System.out.println(S);
    }
}


avatar
Phạm Kim Anh [JavaFree]
2020-03-21 13:27:15



package quanlyhinhhoc;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//tao doi tuong hinh tron
		Circle c = new Circle();
		
		//tao doi tuong hinh chu nhat
		Rectangle r = new Rectangle();
		
		int choose;
		boolean exit = false;
		do {
			menu();
			System.out.println("Moi ban nhap vao lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			
			switch(choose) {
			case 1:
				c.nhap();
				break;
			case 2:
				System.out.println("Chu vi hinh tron = " + c.chuViHT());
				break;
			case 3:
				System.out.println("Dien tich hinh tron = "+c.dienTichHT());
				break;
			case 4:
				r.nhap();
				break;
			case 5:
				System.out.println("Chu vi HCN = "+r.chuViHCN());
				break;
			case 6:
				System.out.println("Dien tich HCN = "+r.dienTichHCN());
				break;
			case 7:
				System.out.println("Cam on da su dung! Tam biet!!!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban nhap lua chon!");
				break;
			}
		}while(choose != 7);
	}
	
	static void menu() {
		System.out.println("=====================================");
		System.out.println("1. Nhap thong tin hinh tron.");
		System.out.println("2. Tinh chu vi hinh tron.");
		System.out.println("3. Tinh dien tich hinh tron.");
		System.out.println("4. Nhap thong tin hinh chu nhat.");
		System.out.println("5. Tinh chu vi hinh chu nhat.");
		System.out.println("6. Tinh dien tich hinh chu nhat.");
		System.out.println("7. Thoat.");
		System.out.println("=====================================");
	}
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Circle {

	float banKinh;
	
	public Circle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param banKinh
	 */
	public Circle(float banKinh) {
		super();
		this.banKinh = banKinh;
	}

	public float getBanKinh() {
		return banKinh;
	}

	public void setBanKinh(float banKinh) {
		this.banKinh = banKinh;
	}
	//tra ve so PI
	static double PI() {
		return Math.PI;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap ban kinh hinh tron: ");
		banKinh = Float.parseFloat(sc.nextLine());
		
	}
	
	//tinh chu vi hinh tron
	double chuViHT() {
		return  2*getBanKinh()*PI();
	}
	
	//tinh dien tich hinh tron
	double dienTichHT() {
		return PI()*getBanKinh()*getBanKinh();
	}
	
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Rectangle {

	float chieuDai;
	float chieuRong;
	
	public Rectangle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param chieuDai
	 * @param chieuRong
	 */
	public Rectangle(float chieuDai, float chieuRong) {
		super();
		this.chieuDai = chieuDai;
		this.chieuRong = chieuRong;
	}

	public float getChieuDai() {
		return chieuDai;
	}

	public void setChieuDai(float chieuDai) {
		this.chieuDai = chieuDai;
	}

	public float getChieuRong() {
		return chieuRong;
	}

	public void setChieuRong(float chieuRong) {
		this.chieuRong = chieuRong;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap chieu dai hinh chu nhat: ");
		chieuDai = Float.parseFloat(sc.nextLine());
		
		System.out.println("Moi ban nhap chieu rong hinh chu nhat: ");
		chieuRong = Float.parseFloat(sc.nextLine());
		
	}
	
	double chuViHCN() {
		return 2*(getChieuDai() + getChieuRong());
	}
	
	double dienTichHCN() {
		return getChieuDai()*getChieuRong();
	}
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Rectangle {

	float chieuDai;
	float chieuRong;
	
	public Rectangle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param chieuDai
	 * @param chieuRong
	 */
	public Rectangle(float chieuDai, float chieuRong) {
		super();
		this.chieuDai = chieuDai;
		this.chieuRong = chieuRong;
	}

	public float getChieuDai() {
		return chieuDai;
	}

	public void setChieuDai(float chieuDai) {
		this.chieuDai = chieuDai;
	}

	public float getChieuRong() {
		return chieuRong;
	}

	public void setChieuRong(float chieuRong) {
		this.chieuRong = chieuRong;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap chieu dai hinh chu nhat: ");
		chieuDai = Float.parseFloat(sc.nextLine());
		
		System.out.println("Moi ban nhap chieu rong hinh chu nhat: ");
		chieuRong = Float.parseFloat(sc.nextLine());
		
	}
	
	double chuViHCN() {
		return 2*(getChieuDai() + getChieuRong());
	}
	
	double dienTichHCN() {
		return getChieuDai()*getChieuRong();
	}
}


package quanlyhinhhoc;

import java.util.Scanner;

public class Circle {

	float banKinh;
	
	public Circle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param banKinh
	 */
	public Circle(float banKinh) {
		super();
		this.banKinh = banKinh;
	}

	public float getBanKinh() {
		return banKinh;
	}

	public void setBanKinh(float banKinh) {
		this.banKinh = banKinh;
	}
	//tra ve so PI
	static double PI() {
		return Math.PI;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap ban kinh hinh tron: ");
		banKinh = Float.parseFloat(sc.nextLine());
		
	}
	
	//tinh chu vi hinh tron
	double chuViHT() {
		return  2*getBanKinh()*PI();
	}
	
	//tinh dien tich hinh tron
	double dienTichHT() {
		return PI()*getBanKinh()*getBanKinh();
	}
	
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//tao doi tuong hinh tron
		Circle c = new Circle();
		
		//tao doi tuong hinh chu nhat
		Rectangle r = new Rectangle();
		
		int choose;
		boolean exit = false;
		do {
			menu();
			System.out.println("Moi ban nhap vao lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			
			switch(choose) {
			case 1:
				c.nhap();
				break;
			case 2:
				System.out.println("Chu vi hinh tron = " + c.chuViHT());
				break;
			case 3:
				System.out.println("Dien tich hinh tron = "+c.dienTichHT());
				break;
			case 4:
				r.nhap();
				break;
			case 5:
				System.out.println("Chu vi HCN = "+r.chuViHCN());
				break;
			case 6:
				System.out.println("Dien tich HCN = "+r.dienTichHCN());
				break;
			case 7:
				System.out.println("Cam on da su dung! Tam biet!!!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban nhap lua chon!");
				break;
			}
		}while(choose != 7);
	}
	
	static void menu() {
		System.out.println("=====================================");
		System.out.println("1. Nhap thong tin hinh tron.");
		System.out.println("2. Tinh chu vi hinh tron.");
		System.out.println("3. Tinh dien tich hinh tron.");
		System.out.println("4. Nhap thong tin hinh chu nhat.");
		System.out.println("5. Tinh chu vi hinh chu nhat.");
		System.out.println("6. Tinh dien tich hinh chu nhat.");
		System.out.println("7. Thoat.");
		System.out.println("=====================================");
	}
}


avatar
Phạm Kim Anh [JavaFree]
2020-03-21 13:27:13



package quanlyhinhhoc;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//tao doi tuong hinh tron
		Circle c = new Circle();
		
		//tao doi tuong hinh chu nhat
		Rectangle r = new Rectangle();
		
		int choose;
		boolean exit = false;
		do {
			menu();
			System.out.println("Moi ban nhap vao lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			
			switch(choose) {
			case 1:
				c.nhap();
				break;
			case 2:
				System.out.println("Chu vi hinh tron = " + c.chuViHT());
				break;
			case 3:
				System.out.println("Dien tich hinh tron = "+c.dienTichHT());
				break;
			case 4:
				r.nhap();
				break;
			case 5:
				System.out.println("Chu vi HCN = "+r.chuViHCN());
				break;
			case 6:
				System.out.println("Dien tich HCN = "+r.dienTichHCN());
				break;
			case 7:
				System.out.println("Cam on da su dung! Tam biet!!!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban nhap lua chon!");
				break;
			}
		}while(choose != 7);
	}
	
	static void menu() {
		System.out.println("=====================================");
		System.out.println("1. Nhap thong tin hinh tron.");
		System.out.println("2. Tinh chu vi hinh tron.");
		System.out.println("3. Tinh dien tich hinh tron.");
		System.out.println("4. Nhap thong tin hinh chu nhat.");
		System.out.println("5. Tinh chu vi hinh chu nhat.");
		System.out.println("6. Tinh dien tich hinh chu nhat.");
		System.out.println("7. Thoat.");
		System.out.println("=====================================");
	}
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Circle {

	float banKinh;
	
	public Circle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param banKinh
	 */
	public Circle(float banKinh) {
		super();
		this.banKinh = banKinh;
	}

	public float getBanKinh() {
		return banKinh;
	}

	public void setBanKinh(float banKinh) {
		this.banKinh = banKinh;
	}
	//tra ve so PI
	static double PI() {
		return Math.PI;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap ban kinh hinh tron: ");
		banKinh = Float.parseFloat(sc.nextLine());
		
	}
	
	//tinh chu vi hinh tron
	double chuViHT() {
		return  2*getBanKinh()*PI();
	}
	
	//tinh dien tich hinh tron
	double dienTichHT() {
		return PI()*getBanKinh()*getBanKinh();
	}
	
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Rectangle {

	float chieuDai;
	float chieuRong;
	
	public Rectangle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param chieuDai
	 * @param chieuRong
	 */
	public Rectangle(float chieuDai, float chieuRong) {
		super();
		this.chieuDai = chieuDai;
		this.chieuRong = chieuRong;
	}

	public float getChieuDai() {
		return chieuDai;
	}

	public void setChieuDai(float chieuDai) {
		this.chieuDai = chieuDai;
	}

	public float getChieuRong() {
		return chieuRong;
	}

	public void setChieuRong(float chieuRong) {
		this.chieuRong = chieuRong;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap chieu dai hinh chu nhat: ");
		chieuDai = Float.parseFloat(sc.nextLine());
		
		System.out.println("Moi ban nhap chieu rong hinh chu nhat: ");
		chieuRong = Float.parseFloat(sc.nextLine());
		
	}
	
	double chuViHCN() {
		return 2*(getChieuDai() + getChieuRong());
	}
	
	double dienTichHCN() {
		return getChieuDai()*getChieuRong();
	}
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Rectangle {

	float chieuDai;
	float chieuRong;
	
	public Rectangle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param chieuDai
	 * @param chieuRong
	 */
	public Rectangle(float chieuDai, float chieuRong) {
		super();
		this.chieuDai = chieuDai;
		this.chieuRong = chieuRong;
	}

	public float getChieuDai() {
		return chieuDai;
	}

	public void setChieuDai(float chieuDai) {
		this.chieuDai = chieuDai;
	}

	public float getChieuRong() {
		return chieuRong;
	}

	public void setChieuRong(float chieuRong) {
		this.chieuRong = chieuRong;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap chieu dai hinh chu nhat: ");
		chieuDai = Float.parseFloat(sc.nextLine());
		
		System.out.println("Moi ban nhap chieu rong hinh chu nhat: ");
		chieuRong = Float.parseFloat(sc.nextLine());
		
	}
	
	double chuViHCN() {
		return 2*(getChieuDai() + getChieuRong());
	}
	
	double dienTichHCN() {
		return getChieuDai()*getChieuRong();
	}
}


package quanlyhinhhoc;

import java.util.Scanner;

public class Circle {

	float banKinh;
	
	public Circle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param banKinh
	 */
	public Circle(float banKinh) {
		super();
		this.banKinh = banKinh;
	}

	public float getBanKinh() {
		return banKinh;
	}

	public void setBanKinh(float banKinh) {
		this.banKinh = banKinh;
	}
	//tra ve so PI
	static double PI() {
		return Math.PI;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap ban kinh hinh tron: ");
		banKinh = Float.parseFloat(sc.nextLine());
		
	}
	
	//tinh chu vi hinh tron
	double chuViHT() {
		return  2*getBanKinh()*PI();
	}
	
	//tinh dien tich hinh tron
	double dienTichHT() {
		return PI()*getBanKinh()*getBanKinh();
	}
	
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//tao doi tuong hinh tron
		Circle c = new Circle();
		
		//tao doi tuong hinh chu nhat
		Rectangle r = new Rectangle();
		
		int choose;
		boolean exit = false;
		do {
			menu();
			System.out.println("Moi ban nhap vao lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			
			switch(choose) {
			case 1:
				c.nhap();
				break;
			case 2:
				System.out.println("Chu vi hinh tron = " + c.chuViHT());
				break;
			case 3:
				System.out.println("Dien tich hinh tron = "+c.dienTichHT());
				break;
			case 4:
				r.nhap();
				break;
			case 5:
				System.out.println("Chu vi HCN = "+r.chuViHCN());
				break;
			case 6:
				System.out.println("Dien tich HCN = "+r.dienTichHCN());
				break;
			case 7:
				System.out.println("Cam on da su dung! Tam biet!!!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban nhap lua chon!");
				break;
			}
		}while(choose != 7);
	}
	
	static void menu() {
		System.out.println("=====================================");
		System.out.println("1. Nhap thong tin hinh tron.");
		System.out.println("2. Tinh chu vi hinh tron.");
		System.out.println("3. Tinh dien tich hinh tron.");
		System.out.println("4. Nhap thong tin hinh chu nhat.");
		System.out.println("5. Tinh chu vi hinh chu nhat.");
		System.out.println("6. Tinh dien tich hinh chu nhat.");
		System.out.println("7. Thoat.");
		System.out.println("=====================================");
	}
}


avatar
Phạm Kim Anh [JavaFree]
2020-03-21 13:26:18



package quanlyhinhhoc;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//tao doi tuong hinh tron
		Circle c = new Circle();
		
		//tao doi tuong hinh chu nhat
		Rectangle r = new Rectangle();
		
		int choose;
		boolean exit = false;
		do {
			menu();
			System.out.println("Moi ban nhap vao lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			
			switch(choose) {
			case 1:
				c.nhap();
				break;
			case 2:
				System.out.println("Chu vi hinh tron = " + c.chuViHT());
				break;
			case 3:
				System.out.println("Dien tich hinh tron = "+c.dienTichHT());
				break;
			case 4:
				r.nhap();
				break;
			case 5:
				System.out.println("Chu vi HCN = "+r.chuViHCN());
				break;
			case 6:
				System.out.println("Dien tich HCN = "+r.dienTichHCN());
				break;
			case 7:
				System.out.println("Cam on da su dung! Tam biet!!!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban nhap lua chon!");
				break;
			}
		}while(choose != 7);
	}
	
	static void menu() {
		System.out.println("=====================================");
		System.out.println("1. Nhap thong tin hinh tron.");
		System.out.println("2. Tinh chu vi hinh tron.");
		System.out.println("3. Tinh dien tich hinh tron.");
		System.out.println("4. Nhap thong tin hinh chu nhat.");
		System.out.println("5. Tinh chu vi hinh chu nhat.");
		System.out.println("6. Tinh dien tich hinh chu nhat.");
		System.out.println("7. Thoat.");
		System.out.println("=====================================");
	}
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Circle {

	float banKinh;
	
	public Circle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param banKinh
	 */
	public Circle(float banKinh) {
		super();
		this.banKinh = banKinh;
	}

	public float getBanKinh() {
		return banKinh;
	}

	public void setBanKinh(float banKinh) {
		this.banKinh = banKinh;
	}
	//tra ve so PI
	static double PI() {
		return Math.PI;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap ban kinh hinh tron: ");
		banKinh = Float.parseFloat(sc.nextLine());
		
	}
	
	//tinh chu vi hinh tron
	double chuViHT() {
		return  2*getBanKinh()*PI();
	}
	
	//tinh dien tich hinh tron
	double dienTichHT() {
		return PI()*getBanKinh()*getBanKinh();
	}
	
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Rectangle {

	float chieuDai;
	float chieuRong;
	
	public Rectangle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param chieuDai
	 * @param chieuRong
	 */
	public Rectangle(float chieuDai, float chieuRong) {
		super();
		this.chieuDai = chieuDai;
		this.chieuRong = chieuRong;
	}

	public float getChieuDai() {
		return chieuDai;
	}

	public void setChieuDai(float chieuDai) {
		this.chieuDai = chieuDai;
	}

	public float getChieuRong() {
		return chieuRong;
	}

	public void setChieuRong(float chieuRong) {
		this.chieuRong = chieuRong;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap chieu dai hinh chu nhat: ");
		chieuDai = Float.parseFloat(sc.nextLine());
		
		System.out.println("Moi ban nhap chieu rong hinh chu nhat: ");
		chieuRong = Float.parseFloat(sc.nextLine());
		
	}
	
	double chuViHCN() {
		return 2*(getChieuDai() + getChieuRong());
	}
	
	double dienTichHCN() {
		return getChieuDai()*getChieuRong();
	}
}


avatar
Phạm Kim Anh [JavaFree]
2020-03-21 13:26:11



package quanlyhinhhoc;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//tao doi tuong hinh tron
		Circle c = new Circle();
		
		//tao doi tuong hinh chu nhat
		Rectangle r = new Rectangle();
		
		int choose;
		boolean exit = false;
		do {
			menu();
			System.out.println("Moi ban nhap vao lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			
			switch(choose) {
			case 1:
				c.nhap();
				break;
			case 2:
				System.out.println("Chu vi hinh tron = " + c.chuViHT());
				break;
			case 3:
				System.out.println("Dien tich hinh tron = "+c.dienTichHT());
				break;
			case 4:
				r.nhap();
				break;
			case 5:
				System.out.println("Chu vi HCN = "+r.chuViHCN());
				break;
			case 6:
				System.out.println("Dien tich HCN = "+r.dienTichHCN());
				break;
			case 7:
				System.out.println("Cam on da su dung! Tam biet!!!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban nhap lua chon!");
				break;
			}
		}while(choose != 7);
	}
	
	static void menu() {
		System.out.println("=====================================");
		System.out.println("1. Nhap thong tin hinh tron.");
		System.out.println("2. Tinh chu vi hinh tron.");
		System.out.println("3. Tinh dien tich hinh tron.");
		System.out.println("4. Nhap thong tin hinh chu nhat.");
		System.out.println("5. Tinh chu vi hinh chu nhat.");
		System.out.println("6. Tinh dien tich hinh chu nhat.");
		System.out.println("7. Thoat.");
		System.out.println("=====================================");
	}
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Circle {

	float banKinh;
	
	public Circle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param banKinh
	 */
	public Circle(float banKinh) {
		super();
		this.banKinh = banKinh;
	}

	public float getBanKinh() {
		return banKinh;
	}

	public void setBanKinh(float banKinh) {
		this.banKinh = banKinh;
	}
	//tra ve so PI
	static double PI() {
		return Math.PI;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap ban kinh hinh tron: ");
		banKinh = Float.parseFloat(sc.nextLine());
		
	}
	
	//tinh chu vi hinh tron
	double chuViHT() {
		return  2*getBanKinh()*PI();
	}
	
	//tinh dien tich hinh tron
	double dienTichHT() {
		return PI()*getBanKinh()*getBanKinh();
	}
	
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Rectangle {

	float chieuDai;
	float chieuRong;
	
	public Rectangle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param chieuDai
	 * @param chieuRong
	 */
	public Rectangle(float chieuDai, float chieuRong) {
		super();
		this.chieuDai = chieuDai;
		this.chieuRong = chieuRong;
	}

	public float getChieuDai() {
		return chieuDai;
	}

	public void setChieuDai(float chieuDai) {
		this.chieuDai = chieuDai;
	}

	public float getChieuRong() {
		return chieuRong;
	}

	public void setChieuRong(float chieuRong) {
		this.chieuRong = chieuRong;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap chieu dai hinh chu nhat: ");
		chieuDai = Float.parseFloat(sc.nextLine());
		
		System.out.println("Moi ban nhap chieu rong hinh chu nhat: ");
		chieuRong = Float.parseFloat(sc.nextLine());
		
	}
	
	double chuViHCN() {
		return 2*(getChieuDai() + getChieuRong());
	}
	
	double dienTichHCN() {
		return getChieuDai()*getChieuRong();
	}
}


avatar
Phạm Kim Anh [JavaFree]
2020-03-21 13:25:54



package quanlyhinhhoc;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//tao doi tuong hinh tron
		Circle c = new Circle();
		
		//tao doi tuong hinh chu nhat
		Rectangle r = new Rectangle();
		
		int choose;
		boolean exit = false;
		do {
			menu();
			System.out.println("Moi ban nhap vao lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			
			switch(choose) {
			case 1:
				c.nhap();
				break;
			case 2:
				System.out.println("Chu vi hinh tron = " + c.chuViHT());
				break;
			case 3:
				System.out.println("Dien tich hinh tron = "+c.dienTichHT());
				break;
			case 4:
				r.nhap();
				break;
			case 5:
				System.out.println("Chu vi HCN = "+r.chuViHCN());
				break;
			case 6:
				System.out.println("Dien tich HCN = "+r.dienTichHCN());
				break;
			case 7:
				System.out.println("Cam on da su dung! Tam biet!!!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban nhap lua chon!");
				break;
			}
		}while(choose != 7);
	}
	
	static void menu() {
		System.out.println("=====================================");
		System.out.println("1. Nhap thong tin hinh tron.");
		System.out.println("2. Tinh chu vi hinh tron.");
		System.out.println("3. Tinh dien tich hinh tron.");
		System.out.println("4. Nhap thong tin hinh chu nhat.");
		System.out.println("5. Tinh chu vi hinh chu nhat.");
		System.out.println("6. Tinh dien tich hinh chu nhat.");
		System.out.println("7. Thoat.");
		System.out.println("=====================================");
	}
}



package quanlyhinhhoc;

import java.util.Scanner;

public class Circle {

	float banKinh;
	
	public Circle() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param banKinh
	 */
	public Circle(float banKinh) {
		super();
		this.banKinh = banKinh;
	}

	public float getBanKinh() {
		return banKinh;
	}

	public void setBanKinh(float banKinh) {
		this.banKinh = banKinh;
	}
	//tra ve so PI
	static double PI() {
		return Math.PI;
	}
	
	public void nhap() {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Moi ban nhap ban kinh hinh tron: ");
		banKinh = Float.parseFloat(sc.nextLine());
		
	}
	
	//tinh chu vi hinh tron
	double chuViHT() {
		return  2*getBanKinh()*PI();
	}
	
	//tinh dien tich hinh tron
	double dienTichHT() {
		return PI()*getBanKinh()*getBanKinh();
	}
	
}


avatar
Phạm Kim Anh [JavaFree]
2020-03-21 13:25:38



package quanlyhinhhoc;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//tao doi tuong hinh tron
		Circle c = new Circle();
		
		//tao doi tuong hinh chu nhat
		Rectangle r = new Rectangle();
		
		int choose;
		boolean exit = false;
		do {
			menu();
			System.out.println("Moi ban nhap vao lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			
			switch(choose) {
			case 1:
				c.nhap();
				break;
			case 2:
				System.out.println("Chu vi hinh tron = " + c.chuViHT());
				break;
			case 3:
				System.out.println("Dien tich hinh tron = "+c.dienTichHT());
				break;
			case 4:
				r.nhap();
				break;
			case 5:
				System.out.println("Chu vi HCN = "+r.chuViHCN());
				break;
			case 6:
				System.out.println("Dien tich HCN = "+r.dienTichHCN());
				break;
			case 7:
				System.out.println("Cam on da su dung! Tam biet!!!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban nhap lua chon!");
				break;
			}
		}while(choose != 7);
	}
	
	static void menu() {
		System.out.println("=====================================");
		System.out.println("1. Nhap thong tin hinh tron.");
		System.out.println("2. Tinh chu vi hinh tron.");
		System.out.println("3. Tinh dien tich hinh tron.");
		System.out.println("4. Nhap thong tin hinh chu nhat.");
		System.out.println("5. Tinh chu vi hinh chu nhat.");
		System.out.println("6. Tinh dien tich hinh chu nhat.");
		System.out.println("7. Thoat.");
		System.out.println("=====================================");
	}
}


avatar
Phạm Kim Anh [JavaFree]
2020-03-21 13:25:37



package quanlyhinhhoc;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//tao doi tuong hinh tron
		Circle c = new Circle();
		
		//tao doi tuong hinh chu nhat
		Rectangle r = new Rectangle();
		
		int choose;
		boolean exit = false;
		do {
			menu();
			System.out.println("Moi ban nhap vao lua chon: ");
			choose = Integer.parseInt(sc.nextLine());
			
			switch(choose) {
			case 1:
				c.nhap();
				break;
			case 2:
				System.out.println("Chu vi hinh tron = " + c.chuViHT());
				break;
			case 3:
				System.out.println("Dien tich hinh tron = "+c.dienTichHT());
				break;
			case 4:
				r.nhap();
				break;
			case 5:
				System.out.println("Chu vi HCN = "+r.chuViHCN());
				break;
			case 6:
				System.out.println("Dien tich HCN = "+r.dienTichHCN());
				break;
			case 7:
				System.out.println("Cam on da su dung! Tam biet!!!");
				exit = true;
				break;
			default:
				System.out.println("Moi ban nhap lua chon!");
				break;
			}
		}while(choose != 7);
	}
	
	static void menu() {
		System.out.println("=====================================");
		System.out.println("1. Nhap thong tin hinh tron.");
		System.out.println("2. Tinh chu vi hinh tron.");
		System.out.println("3. Tinh dien tich hinh tron.");
		System.out.println("4. Nhap thong tin hinh chu nhat.");
		System.out.println("5. Tinh chu vi hinh chu nhat.");
		System.out.println("6. Tinh dien tich hinh chu nhat.");
		System.out.println("7. Thoat.");
		System.out.println("=====================================");
	}
}