??? @Override ??? public int hashCode() ??? { ??????? final int prime = 31; ??????? int result = 1; ??????? result = prime * result ??????????????? + ((centerPoint == null) ? 0 : centerPoint.hashCode()); ??????? long temp; ??????? temp = Double.doubleToLongBits( radius ); ??????? result = prime * result + (int)(temp ^ (temp >>> 32)); ??????? return result; ??? }
??? @Override ??? public boolean equals( Object obj ) ??? { ??????? if ( this == obj ) ??????????? return true; ??????? if ( obj == null ) ??????????? return false; ??????? if ( getClass() != obj.getClass() ) ??????????? return false; ??????? Circle other = (Circle)obj; ??????? if ( centerPoint == null ) ??????? { ??????????? if ( other.centerPoint != null ) ??????????????? return false; ??????? } else if ( !centerPoint.equals( other.centerPoint ) ) ??????????? return false; ??????? if ( Double.doubleToLongBits( radius ) != Double ??????????????? .doubleToLongBits( other.radius ) ) ??????????? return false; ??????? return true; ??? }
??? public static void main( String[] args ) ??? { ??????? Circle circle = new Circle( "a1", 10 ); ??????? System.out.println( circle );
2016-04-24
package com.imooc;
import java.util.Scanner;
public class Circle {
/*
* 關(guān)于圓的計(jì)算問題:
*
* */
final double PI=3.14;//用final修飾,代表常量值,不可改變
//創(chuàng)建一個(gè)輸入的對(duì)象、動(dòng)態(tài)給定值(因?yàn)橛袃蓚€(gè)方法,將這個(gè)定成全局的)
Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
//實(shí)例化對(duì)象
Circle cl=new Circle();
//調(diào)用方法執(zhí)行
cl.getZC();//計(jì)算周長
cl.getAcreage();//計(jì)算面積
}
//創(chuàng)建一個(gè)計(jì)算的周長的方法(2*PI*r)
public void getZC(){
//提示輸入
System.out.println("請(qǐng)輸入圓的半徑:");
//定義圓的半徑
int r=sc.nextInt();
//定義一個(gè)變量計(jì)算周長
double zc=2*PI*r;
System.out.println("圓的周長為:"+zc);
}
//創(chuàng)建一個(gè)計(jì)算半徑的方法
public void getAcreage(){
//提示輸入
System.out.println("請(qǐng)輸入圓的半徑:");
//定義圓的半徑
int r=sc.nextInt();
//定義一個(gè)變量計(jì)算周長
double Acreage=PI*r*r;
System.out.println("圓的面積為:"+Acreage);
}
}
2016-04-13
public class Circle {
? ?private double radius;
? ?public Circle(double radius) {
? ? ? ?this.radius = radius;
? ?}
? ?public double getPerimeter() {
? ? ? ?return 2 * Math.PI * radius;
? ?}
? ?public double getArea() {
? ? ? ?return Math.PI * radius * radius;
? ?}
? ?
? ?public static void main(String[] args) {
? ? ? ?Circle c = new Circle(1.28);
? ? ? ?System.out.printf("圓的周長: %.2f\n", c.getPerimeter());
? ? ? ?System.out.printf("圓的面積: %.2f\n", c.getArea());
? ?}
}
2016-04-12
2016-04-12
public class Yuan
{
? ? public static void main(String[] args)
? ? {
? ? ? ? // TODO 自動(dòng)生成的方法存根
? ? ? ? double r=4;// 半徑
? ? ? ? double L=2 * Math.PI * r;
? ? ? ? double S=Math.PI * r * r;
? ? ? ? System.out.println("圓周長是:" + L);
? ? ? ? System.out.println("圓面積是:" + S);
? ? }
}
2016-04-12
package com.basic;
import com.basic.InnerClass.Inner;
/**
?* 圓類,以圓心和半徑來區(qū)分兩個(gè)圓是否相同。
?*
?* @author Administrator
?*/
public class Circle
{
??? private static final int CONSTANT_TWO = 2;
??? /**
???? * 圓心
???? */
??? private String centerPoint;
??? /**
???? * 半徑
???? */
??? private double radius;
??? /**
???? * 無參構(gòu)造器
???? */
??? public Circle()
??? {
??? }
??? /**
???? * 有參構(gòu)造器
???? *
???? * @param centerPoint
???? *??????????? 圓心(可以繼續(xù)封裝成坐標(biāo))
???? * @param radius
???? *??????????? 半徑
???? */
??? public Circle( String centerPoint,double radius )
??? {
??????? super();
??????? this.centerPoint = centerPoint;
??????? this.radius = radius;
??? }
??? /**
???? * 獲取圓心值
???? *
???? * @return 圓心值
???? */
??? private String getCenterPoint()
??? {
??????? return centerPoint;
??? }
??? /**
???? * 設(shè)置圓心值
???? *
???? * @param centerPoint
???? */
??? private void setCenterPoint( String centerPoint )
??? {
??????? this.centerPoint = centerPoint;
??? }
??? /**
???? * 獲取圓半徑
???? *
???? * @return
???? */
??? private double getRadius()
??? {
??????? return radius;
??? }
??? /**
???? * 設(shè)置圓半徑
???? *
???? * @param radius
???? */
??? private void setRadius( long radius )
??? {
??????? this.radius = radius;
??? }
??? /**
???? * 計(jì)算圓周長
???? *
???? * @return
???? */
??? public double caculatePerimeter()
??? {
??????? return Math.PI * this.radius * CONSTANT_TWO;
??? }
??? /**
???? * 計(jì)算圓面積
???? *
???? * @return
???? */
??? public double caculateArea()
??? {
??????? return Math.PI * this.radius * this.radius;
??? }
??? /**
???? * 重寫圓類的toString方法
???? */
??? @Override
??? public String toString()
??? {
??????? return "Circle [centerPoint=" + centerPoint + ", radius=" + radius
??????????????? + "]";
??? }
??? @Override
??? public int hashCode()
??? {
??????? final int prime = 31;
??????? int result = 1;
??????? result = prime * result
??????????????? + ((centerPoint == null) ? 0 : centerPoint.hashCode());
??????? long temp;
??????? temp = Double.doubleToLongBits( radius );
??????? result = prime * result + (int)(temp ^ (temp >>> 32));
??????? return result;
??? }
??? @Override
??? public boolean equals( Object obj )
??? {
??????? if ( this == obj )
??????????? return true;
??????? if ( obj == null )
??????????? return false;
??????? if ( getClass() != obj.getClass() )
??????????? return false;
??????? Circle other = (Circle)obj;
??????? if ( centerPoint == null )
??????? {
??????????? if ( other.centerPoint != null )
??????????????? return false;
??????? } else if ( !centerPoint.equals( other.centerPoint ) )
??????????? return false;
??????? if ( Double.doubleToLongBits( radius ) != Double
??????????????? .doubleToLongBits( other.radius ) )
??????????? return false;
??????? return true;
??? }
??? public static void main( String[] args )
??? {
??????? Circle circle = new Circle( "a1", 10 );
??????? System.out.println( circle );
??????? double perimeter = circle.caculatePerimeter();
??????? System.out.println( circle + "的周長為:" + perimeter );
??????? double area = circle.caculateArea();
??????? System.out.println( circle + "的面積為:" + area );
??? }
}
2016-04-12
import java.util.Scanner;
public class HelloWorld {
?? ?public static void main(String[] args) {
?? ??? ?double π = 3.14;
?? ??? ?double r;
?? ??? ?double l;
?? ??? ?double s;
?? ??? ?Scanner sc = new Scanner(System.in);
?? ??? ?sc.useDelimiter("\n");
?? ??? ?while(sc.hasNext()){
?? ??? ??? ?r=Double.parseDouble(sc.nextLine());
?? ??? ??? ?l=2*Math.PI*r;;
?? ??? ??? ?s=Math.PI*r*r;;
?? ??? ??? ?System.out.println("周長是:" + l);
?? ??? ??? ?System.out.println("面積是:" + s);
?? ??? ?}
?? ??? ??? ?
?? ?}
?? ?
}
2016-04-12
class A{
????????private float r;
????????public float getR(){
????????return r;
????????}
????????public void setR(float r){
????????this.r = r;
????????}
????????public float Area(){
????????return (float)(3.14*r*r);
????????}
????????public float Circumf(){
????????return (float)3.14*2*r;
????????}
}
public class Circle {
????????public static void main(String[] args) {
????????A a = new A();
????????a.setR(4);
????????System.out.println(a.Area());
????????System.out.println(a.Circumf());
????????}
}
2016-04-12
//創(chuàng)建圓型類
class ?circle?
{ ??
//創(chuàng)建 ?算周長方式 傳出半徑算周長
?????public double void setPerimeter(?double?radii??)
?????{?
? ?//
? ? ? ?double?π = 3.14159265358979323846;
? ? ? ?double?perimeter=?radii *2*π ;
? ? ? ?retuan?perimeter ;
? ? ?}
//創(chuàng)建 ?算周長方式 傳出半徑算面積
public double void setAcreage(?double?radii??)
?????{ ?double?π = 3.14159265358979323846;
? ? ? ?double?acreage=?radii *radii?*π ;
? ? ? ?retuan?acreager ;
? ? ?}
}