沒(méi)明白isLargeThan是什么意思,能說(shuō)得詳細(xì)點(diǎn)兒么?
成都創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站制作、網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)金寨,10多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):18982081108
先把滿足前四個(gè)條件的程序發(fā)給你,你看看行不行。
注:一個(gè)類一個(gè)java文件,運(yùn)行Test3類執(zhí)行。
public class Point {
private double x;
private double y;
public Point() {
x=0;
y=0;
}
public Point(double x,double y){
this.x=x;
this.y=y;
}
public double getX(){
return this.x;
}
public double getY(){
return this.y;
}
public void setX(double x){
this.x=x;
}
public void setY(double y){
this.y=y;
}
public Point translate(double u,double v){
this.x=this.x+u;
this.y=this.y+v;
return new Point (this.x,this.y);
}
}
public class Rectangle extends Point {
private double height;
private double wideth;
public Rectangle() {
super();
}
public Rectangle(Point p,double h,double w){
super(p.getX(),p.getY());
this.height=h;
this.wideth=w;
}
public double getPerimeter(){
return 2*(height+wideth);
}
public double getArea(){
return height*wideth;
}
}
public class Ellipse extends Point{
private double height;
private double wideth;
public Ellipse() {
super();
}
public Ellipse(Point p,double h,double w){
super(p.getX(),p.getY());
this.height=h;
this.wideth=w;
}
public double getPerimeter(){
return 2*3.14*Math.sqrt((height*height+wideth*wideth)/2);
}
public double getArea(){
return 3.14*height*wideth;
}
}
public class Test3 {
public static void main(String[] args) {
Point p=new Point(1.2,4.6);
Rectangle r=new Rectangle(p,9.2,8.7);
Ellipse e=new Ellipse(p,3.2,9.2);
Point p1=p.translate(2.8,2.9);
System.out.println("移動(dòng)后的點(diǎn)為x="+p1.getX()+" y="+p1.getY());
System.out.println("長(zhǎng)方形的周長(zhǎng)為:"+r.getPerimeter());
System.out.println("長(zhǎng)方形的面積為:"+r.getArea());
System.out.println("橢圓形的周長(zhǎng)為:"+e.getPerimeter());
System.out.println("橢圓形的面積為:"+e.getArea());
}
}
class ChangFangXing{
private int length;
private int width;
public ChangFangXing(){}
public void setLength(int length){
this.length = length;
}
public void setWidth(int width){
this.width = width;
}
//求周長(zhǎng)
public int getZhouChang(){
return (length + width)*2;
}
public int getArea(){
return length * width;
}
}
class ChangFangXingDemo{
public static void main(String[] args){
ChangFangXing s = new ChangFangXing();
s.setLength(5);
s.setWidth(6);
System.out.println("長(zhǎng)方形的周長(zhǎng)為:"+s.getZhouChang());
System.out.println("長(zhǎng)方形的面積為:"+s.getArea());
}
}
//看看我這個(gè)程序把 比較符合面向?qū)ο蟮乃枷耄嬖V摟住一聲,盡量把一些程序?qū)懕M方法里,而不是都寫在主方法中!這樣不好~~~~ 希望對(duì)你有用!!
import java.util.Scanner;
public class Ex {
public static int squ(int x,int y){ //求面積的方法
int s = x* y;
return s;
}
public static double len(int x,int y){//求周長(zhǎng)的方法
int l = (x+y)*2;
return l;
}
public static void main(String [] aa){
System.out.println("請(qǐng)輸入寬:"); //從命令行輸入寬
Scanner in = new Scanner(System.in);
int le = in.nextInt();
System.out.println("請(qǐng)輸入高:");//從命令行輸入高
Scanner in2 = new Scanner(System.in);
int hi = in2.nextInt(); //轉(zhuǎn)換為int型
int mianji = squ(le,hi); //調(diào)用方法
System.out.println("面積是:" + mianji);
/*
* 求周長(zhǎng)同理,調(diào)用周長(zhǎng)那個(gè)方法即可
*/
}
}
//計(jì)算矩形的面積
public class RectArea {
public static double getArea(double width, double higth) {
double area = 0.0;// 矩形面積
// 判斷輸入是否合理
if (!(width = 0 || higth = 0)) {
area = width * higth;
return area;// 返回面積
} else {
System.out.println("請(qǐng)輸入合理的長(zhǎng)寬");
return -1;
}
}
public static void main(String[] args) {
//測(cè)試 寬:10.0 高:20.0
System.out.println("矩形面積" + RectArea.getArea(10.0, 20.0));
}
}
import java.util.*;
public class Rectangle {
private float length; //定義長(zhǎng)變量
private float width; // 寬變量
public Rectangle(float length,float width){
this.length=length;
this.width=width;
}
public float getGirth(){
return (length+width)*2;
} //求周長(zhǎng)方法
public float getArea(){
return length*width;
} //求面積方法
public static void main (String[] args) {
Scanner in=new Scanner(System.in);//調(diào)用輸入方法
System.out.println ("請(qǐng)輸入矩形的長(zhǎng):");
float a=in.nextFloat();
System.out.println ("請(qǐng)輸入矩形的寬:");
float b=in.nextFloat();
System.out.println ("矩形周長(zhǎng)為:"+new Rectangle(a,b).getGirth());
System.out.println ("矩形面積為:"+new Rectangle(a,b).getArea());
}
}
// 父類Sharp 如下:public abstract class Sharp {
// 定義面積方法
public abstract double area();
} // 子類RectSharp 繼承父類:public class RectSharp extends Sharp { private double width, heigth; public RectSharp(double width, double heigth) {
this.width = width;
this.heigth = heigth;
} /**
* 求出面積
*/
@Override
public double area() {
return width * heigth;
} public static void main(String[] args) {
// 創(chuàng)建一個(gè)長(zhǎng)方形類
RectSharp r = new RectSharp(100, 50.2);
// 計(jì)算面積
double area = r.area();
System.out.println("該長(zhǎng)方形的面積為:" + area);
}
}