创建描述泵的属性(转速,压力,重量,排量,脉动)的类
定义描述泵类型的构造方法,含有唯一参数:泵的类型字符串
/**
* this is a class definition discribing the properties of a pump
* @author XYM_
* @date 2021-4-12
* @version 1.0
*/
import java.io.*
public class Pump{
//PumpRev rotate speed of pump
int PumpRev;
//OutputPressure output pressure of pump
double OutputPressure;
//PumpWeight weight of pump
double PumpWeight;
//PumpDisplacement displacement of pump
double PumpDisplacement;
//PumpPulsation pressure pulsation of pump
double PumpPulsation;
/**
* this is a constructor of pump
* @param name type name of pump
*/
public Pump(String name){
// print the name
System.out.println("Type of pump:" + name);
}
/**
* set the value of PumpRev
* @param n rotate speed of pump
* @author XYM_
* @return value of PumpRev
* @version 1.0
*/
public int setN( int n ){
PumpRev = n;
// print the rotate speed
System.out.println("Rotate speed:" + PumpRev + "rpm");
return PumpRev;
}
/**
* set the value of OutputPressure
* @param p output pressure of pump
* @author XYM_
* @return value of OutputPressure
* @version 1.0
*/
public double setP( double p ){
OutputPressure = p;
// print the output pressure
System.out.println("Output pressure:" + OutputPressure + "MPa");
return OutputPressure;
}
/**
* set the value of PumpWeight
* @param w weight of pump
* @author XYM_
* @return value of PumpWeight
* @version 1.0
*/
public double setW( double w ){
PumpWeight = w;
// print the weight
System.out.println("Weught:" + PumpWeight + "kg");
return PumpWeight;
}
/**
* set the value of PumpDisplacement
* @param q displacement of pump
* @author XYM_
* @return value of PumpDisplacement
* @version 1.0
*/
public double setQ( double q ){
PumpDisplacement = q;
// print the displacement
System.out.println("Displacement:" + PumpDisplacement + "ml/rev");
return PumpDisplacement;
}
/**
* set the value of PumpPulsation
* @param tau pressure pulsation of pump
* @author XYM_
* @return value of PumpPulsation
* @version 1.0
*/
public double setTau( double tau ){
PumpPulsation = tau;
// print the pressure pulsation
System.out.println("Pulsation:" + PumpPulsation + "%");
return PumpPulsation;
}
}
测试代码为:
/**
* this is a test class
* @author XYM_
* @date 2021-4-12
* @version 1.0
*/
import java.io.*;
public class PumpTest{
public static void main(String[] args){
Pump pump01 = new Pump("swashplate pump");
pump01.setN(4200);
pump01.setP(21.5d);
pump01.setW(9.8d);
pump01.setQ(19.5d);
pump01.setTau(4d);
Pump pump02 = new Pump("swashplate pump");
pump02.setN(4000);
pump02.setP(28d);
pump02.setW(15.3d);
pump02.setQ(75d);
pump02.setTau(4d);
}
}
运行结果为:
Type of pump:swashplate pump
Rotate speed:4200rpm
Output pressure:21.5MPa
Weught:9.8kg
Displacement:19.5ml/rev
Pulsation:4.0%
Type of pump:swashplate pump
Rotate speed:4000rpm
Output pressure:28.0MPa
Weught:15.3kg
Displacement:75.0ml/rev
Pulsation:4.0%