风扇与线性方程


Javadoc/UML




public class Fan {

      public staticfinal int SLOW=1;

      public staticfinal int MEDIUM=2;

      public staticfinal int FAST=3;

      private intspeed=SLOW;       //速度

      private booleanon=false;           //是否打开

      private doubleradius=5;        //半径

      private Stringcolor="bule";         //颜色

      public Fan() {

      }

      public intgetSpeed() {

           return speed;

      }

      public voidsetSpeed(int speed) {

           this.speed= speed;

      }

      public booleanisOn() {

           return on;

      }

      public voidsetOn(boolean on) {

           this.on =on;

      }

      public doublegetRadius() {

           returnradius;

      }

      public voidsetRadius(double radius) {

           this.radius= radius;

      }

      public StringgetColor() {

           returncolor;

      }

      public voidsetColor(String color) {

           this.color= color;

      }

 

      @Override

      public StringtoString() {

           if(this.on){

           return"Fan [speed=" + speed + ", radius=" + radius

                      +", color=" + color + " , 电扇打开了.]";}

           elsereturn "电扇没有打开."+"Fan [ radius=" + radius

                      +", color=" + color + "]";

}

}

package gkm;

 

public class TestFan {

      public staticvoid main(String[] args) {

           // TODOAuto-generated method stub

           Fanfan1=new Fan();

           fan1.setSpeed(Fan.FAST);

           fan1.setColor("黄色");

           fan1.setRadius(10);

           fan1.setOn(true);

           Fanfan2=new Fan();

           System.out.println(fan1);

 

      }

}

(2)线性方程

package gkm

public class LinearEquation {

      private doublea;

      private doubleb;

      private doublec;

      private doubled;

      private doublee;

      private doublef;

      publicLinearEquation(double a, double b,double c,double d,double e,double f){

           this.a =a;

           this.b =b;

           this.c =c;

           this.d =d;

           this.e =e;

           this.f =f;

      }

      public doublegetA() {

           return a;

      }

      public voidsetA(double a) {

           this.a =a;

      }

      public doublegetB() {

           return b;

      }

      public voidsetB(double b) {

           this.b =b;

      }

      public doublegetC() {

           return c;

      }

      public voidsetC(double c) {

           this.c =c;

      }

      public doublegetD() {

           return d;

      }

      public voidsetD(double d) {

           this.d =d;

      }

      public doublegetE() {

           return e;

      }

 

 

      public voidsetE(double e) {

           this.e =e;

      }

 

 

      public doublegetF() {

           return f;

      }

      public voidsetF(double f) {

           this.f =f;

      }

      public booleanisSolvable(){

           if((a*d-b*c)!=0)return true;

           elsereturn false;

      }

      public doublegetx(){

           if(isSolvable())

                 return(e*d-b*f)/(a*d-b*c);

           elsereturn 0;

      }

      public doublegety(){

           if(isSolvable())

                 return(a*f-e*c)/(a*d-b*c);

           elsereturn 0;

      }

      @Override

      public StringtoString() {

           if(this.isSolvable())

                 return"线性方程的解是X="+getx()+",Y="+gety();

           elsereturn "线性方程无解";

          

      }

}

package gkm;

 

import java.util.Scanner;

 

public class TestLinearEquation {

 

      public staticvoid main(String[] args) {

           Scanner input=newScanner(System.in);

           System.out.println("请输入线性方程的参数a,b,c,d,e,f");

           inta=input.nextInt();

           intb=input.nextInt();

           intc=input.nextInt();

           intd=input.nextInt();

           inte=input.nextInt();

           intf=input.nextInt();

           LinearEquationIe1=new LinearEquation(a,b,c,d,e,f);

           System.out.println(Ie1);

      }

}

(3)二元方程

package gkm;

public class LineBy2Point {

      private PointstartPoint;

      private PointendPoint;

      publicLineBy2Point() {

           // TODOAuto-generated constructor stub

      }

     

      publicLineBy2Point(Point startPoint, Point endPoint) {

           this.startPoint= startPoint;

           this.endPoint= endPoint;

      }

     

      publicLineBy2Point(double x1,double y1,double x2,double y2){

           this.startPoint=newPoint(x1,y1);

           this.endPoint=newPoint(x2,y2);

      }

     

      public PointcomputeCrossPoint(LineBy2Point anotherline){

           doublea=this.startPoint.getY()-this.endPoint.getY();

           doubleb=this.endPoint.getX()-this.startPoint.getX();

           doublec=anotherline.startPoint.getY()-anotherline.endPoint.getY();

           doubled=anotherline.endPoint.getX()-anotherline.startPoint.getX();

           doublee=this.endPoint.getX()*this.startPoint.getY()

                      -this.startPoint.getX()*this.endPoint.getY();

           doublef=anotherline.endPoint.getX()*anotherline.startPoint.getY()

                      -anotherline.startPoint.getX()*anotherline.endPoint.getY();

          

           LinearEquationIe=new LinearEquation(a,b,c,d,e,f);

          

           if(Ie.isSolvable()){

                 PointcrossPoint=new Point(Ie.getx(),Ie.gety());

                 returncrossPoint;

           }

           elsereturn null;

      }

}

package gkm;

import java.util.Scanner;

public class TestPoint {

      public staticvoid main(String[] args) {

           // TODOAuto-generated method stub

           Scannerinput=new Scanner(System.in);

           doublex1,x2,x3,x4,y1,y2,y3,y4;

           System.out.print("请输入第一条线的起点");

           x1=input.nextDouble();

           y1=input.nextDouble();

           System.out.print("请输入第一条线的终点");

           x2=input.nextDouble();

           y2=input.nextDouble();

           System.out.print("请输入第二条线的起点");

           x3=input.nextDouble();

           y3=input.nextDouble();

           System.out.print("请输入第二条线的终点");

           x4=input.nextDouble();

           y4=input.nextDouble();

           

           LineBy2Pointline1=new LineBy2Point(x1,y1,x2,y2);

           LineBy2Pointline2=new LineBy2Point(x3,y3,x4,y4);

           PointcrossPoint=line1.computeCrossPoint(line2);

           if(crossPoint!=null)

                 System.out.println("交点"+crossPoint);

           elseSystem.out.println("两线没有交点");

      }

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值