Bài Đang S A

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

*shape:

import java.util.Scanner;
public class shape {
String color;
boolean filled;
double radius;
double Area;
double Perimeter;
public shape(String color,boolean filled,double radius, double Area,double
Perimeter) {
this.color = color;
this.filled = filled;
this.radius = radius;
this.Area = Area;
this.Perimeter = Perimeter;
}
public shape() {}
public void input() {
System.out.println("color:"+this.color+";filled:"+this.filled);

}
public String getcolor() {
return color;
}
public void setcolor(String color) {
this.color = color;
}
public boolean getfilled() {
return filled;
}
public void setfilled(boolean filled) {
this.filled = filled;
}

public void Rectangle( double width ,double length) {


}
public void circle(double radius) {

}
class circle extends shape{
double radius;
double Area;
double Perimeter;
String color;
boolean filled;
public circle() {}
public circle(double radius,double Area,double Perimeter) {}
public circle(double radius,String color,boolean filled,double Area,double
Perimeter) {}
public double getradius() {
return radius;
}
public void setradius(double radius) {
this.radius = radius;
}
public double getArea() {
return Area;
}
public void setArea(double Area) {
this.Area = Area;
}

public double getPerimeter() {


return Perimeter;
}
public void setPerimeter(double Perimeter) {
this.Perimeter = Perimeter;
}
public String toString() {
return color+""+filled+""+radius;
}
public void setlength(double nextDouble) {
// TODO Auto-generated method stub

}
}
class rectangle extends shape{
double width;
double length;
double Area;
double Perimeter;
public rectangle() {}
public rectangle(double width,double length,double Area,double Perimeter) {}
public rectangle(double width,double length,String color,boolean filled) {}
public double getwidth() {
return width;
}
public void setwidth(double width) {
this.width = width;
}
public double getlength() {
return length;
}
public void setlength(double length) {
this.length = length;
}

public double getArea() {


return Area;
}
public void setArea(double Area) {
this.Area = Area;
}
public double getPerimeter() {
return Perimeter;
}
public void setPerimeter(double Perimeter) {
this.Perimeter = Perimeter;
}
public String toString() {
return color+""+filled+""+width+""+length;
}
}
class square extends rectangle{
double width ;
double length;
public square() {
super();
}
public square(double side) {
}
public square(double side,String color,boolean filled) {
}

public void setSide(double side) {


super.setlength(side);
super.setwidth(side);
}
public double width() {
return width;
}
public void setwidth(double side,double width) {
this.width = width;
}
public double length() {
return length;
}
public void setlength(double side, double length) {

this.length = length;
}
public String toString() {
return color+""+filled+""+width+""+length;}
public void main(String[]args) {
double width = 1.0;
double length = 1.0;
double radius = 1.0;
Rectangle hcn = new Rectangle(double width ,double length);
Circle ht = new Circle(double radius);
Scanner scanner = new Scanner(System.in);

System.out.println("nhập chiều rộng:");


hcn.setwidth(scanner.nextDouble());
System.out.println("nhập chiều dài:");
hcn.setlength(scanner.nextDouble());

System.out.println("nhập bán kính:");


ht.setradius(scanner.nextDouble());
System.out.println("chu vi hình chữ nhật:"+ hcn.Perimeter());
System.out.println("diện tích hình chữ nhật:"+ hcn.Area());
System.out.println("chu vi hình tròn :"+ ht.Perimeter());
System.out.println("diện tích hình tròn"+ ht.Area());
}
}

*hình chữ nhật:


import java.util.Scanner;
public class Rectangle {
double width;
double length ;
double Area;
double Perimeter;
public double getlength() {
return length;
}
public void setlength(double length) {
this.length = length;
}
public double getwidth() {
return width;
}
public void setwidth(double width) {
this.width = width;
}
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
public double Perimeter() {
return (length+width)*2;
}
public double Area() {
return length*width;
}
public static void main(String[] args) {
double width = 1.0;
double length = 2.0;
Rectangle hcn = new Rectangle(length , width);
Scanner scanner = new Scanner(System.in);
System.out.println("nhập vào chiều dài : ");
hcn.setlength(scanner.nextDouble());
System.out.println("nhập vào chiều rộng : ");
hcn.setwidth(scanner.nextDouble());
System.out.println("chu vi hình chữ nhật là : " +
hcn.Perimeter());
System.out.println("diện tích hình chữ nhật là : " + hcn.Area());
}
}
*hình tròn:
import java.util.Scanner;
public class Circle {
static double radius;
double Perimeter;
double Area;
private Object Circle;
public double getradius() {
return radius;
}
public void setradius(double radius) {
this.radius = radius;
}
public Circle(double radius) {
this.Circle = Circle;
}
public double Perimeter() {
return radius*2*Math.PI;
}
public double Area() {
return radius*radius*Math.PI;
}
public static void main(String[] args) {
// TODO Auto-generated method stub double
radius = 1.0;
Circle ht = new Circle( radius);
Scanner scanner = new Scanner(System.in);
System.out.println("nhap ban kinh : ");
ht.setradius(scanner.nextDouble());
System.out.println("chu vi hinh tron la : " + ht.Perimeter());
System.out.println("dien tich hinh tron la : " + ht.Area());
}

color: }
import java. util.Scanner;
public class color {
private String tenmau;
@Override
public String toString() {

return " color [tenmau=" + tenmau + ", mamau=" + mamau + "]";


}
private int mamau;
public color (String tenmau, int mamau) {

this.tenmau = tenmau;
this.mamau = mamau;
}
public color () {
}
public String getTenmau() {
return tenmau;
}
public void setTenmau(String tenmau) {
this.tenmau = tenmau;
}
public int getMamau() {
return mamau;
}
public void setMamau(int mamau) {
this.mamau = mamau;
}
public void nhap() {
Scanner sc = new Scanner (System.in);
System.out.println("nhap tenmau");
this.tenmau = sc.nextLine();
System.out.println("nhap mamau");
this.mamau = sc.nextInt();
}
}

double width = 1.0;

double length = 1.0;

double radius = 1.0;

rectangle hcn = new rectangle( width , length, color, filled);

circle ht = new circle( color, filled, radius);

Scanner scanner = new Scanner(System.in);

System.out.println("nhập chiều rộng:");

hcn.setwidth(scanner.nextDouble());

System.out.println("nhập chiều dài:");

hcn.setlength(scanner.nextDouble());

System.out.println("nhập bán kính:");

ht.setradius(scanner.nextDouble());

System.out.println("chu vi hình chữ nhật:"+ hcn.Perimeter());

System.out.println("diện tích hình chữ nhật:"+ hcn.Area());


System.out.println("chu vi hình tròn :"+ ht.Primeter());

System.out.println("diện tích hình tròn"+ ht.Area());

ublic class MainClass {


public static void main(String[] args) {
// Thử nghiệm với lớp Hình tròn
HinhTron hinhTron = new HinhTron();
hinhTron.xuatTen();
hinhTron.nhapBanKinh();
hinhTron.tinhChuVi();
hinhTron.tinhDienTich();
hinhTron.inChuVi();
hinhTron.inDienTich();
// Thử nghiệm với lớp Hình trụ
HinhTru hinhTru = new HinhTru();
hinhTru.xuatTen();
hinhTru.nhapChieuCao();
hinhTru.tinhTheTich();
hinhTru.inTheTich();
// Thử nghiệm với lớp Hình chữ nhật
HinhChuNhat hinhChuNhat = new HinhChuNhat();
hinhChuNhat.xuatTen();
hinhChuNhat.nhapChieuDai();
hinhChuNhat.nhapChieuRong();
hinhChuNhat.tinhChuVi();
hinhChuNhat.tinhDienTich();
hinhChuNhat.inChuVi();
hinhChuNhat.inDienTich();
// Thử nghiệm với lớp Hình vuông
HinhVuong hinhVuong = new HinhVuong();
hinhVuong.xuatTen();
hinhVuong.nhapCanh();
hinhVuong.tinhChuVi();
hinhVuong.tinhDienTich();
hinhVuong.inChuVi();
hinhVuong.inDienTich();
}
}

You might also like