大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
没明白isLargeThan是什么意思,能说得详细点儿么?
成都创新互联公司主要从事成都网站制作、网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务金寨,10多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108
先把满足前四个条件的程序发给你,你看看行不行。
注:一个类一个java文件,运行Test3类执行。
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("移动后的点为x="+p1.getX()+" y="+p1.getY());
System.out.println("长方形的周长为:"+r.getPerimeter());
System.out.println("长方形的面积为:"+r.getArea());
System.out.println("椭圆形的周长为:"+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;
}
//求周长
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("长方形的周长为:"+s.getZhouChang());
System.out.println("长方形的面积为:"+s.getArea());
}
}
//看看我这个程序把 比较符合面向对象的思想,告诉搂住一声,尽量把一些程序写尽方法里,而不是都写在主方法中!这样不好~~~~ 希望对你有用!!
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){//求周长的方法
int l = (x+y)*2;
return l;
}
public static void main(String [] aa){
System.out.println("请输入宽:"); //从命令行输入宽
Scanner in = new Scanner(System.in);
int le = in.nextInt();
System.out.println("请输入高:");//从命令行输入高
Scanner in2 = new Scanner(System.in);
int hi = in2.nextInt(); //转换为int型
int mianji = squ(le,hi); //调用方法
System.out.println("面积是:" + mianji);
/*
* 求周长同理,调用周长那个方法即可
*/
}
}
//计算矩形的面积
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("请输入合理的长宽");
return -1;
}
}
public static void main(String[] args) {
//测试 宽:10.0 高:20.0
System.out.println("矩形面积" + RectArea.getArea(10.0, 20.0));
}
}
import java.util.*;
public class Rectangle {
private float length; //定义长变量
private float width; // 宽变量
public Rectangle(float length,float width){
this.length=length;
this.width=width;
}
public float getGirth(){
return (length+width)*2;
} //求周长方法
public float getArea(){
return length*width;
} //求面积方法
public static void main (String[] args) {
Scanner in=new Scanner(System.in);//调用输入方法
System.out.println ("请输入矩形的长:");
float a=in.nextFloat();
System.out.println ("请输入矩形的宽:");
float b=in.nextFloat();
System.out.println ("矩形周长为:"+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) {
// 创建一个长方形类
RectSharp r = new RectSharp(100, 50.2);
// 计算面积
double area = r.area();
System.out.println("该长方形的面积为:" + area);
}
}