📄 juice.java
字号:
package problem_11_1;
//Juice.java
public class Juice {
private double sugarAmount; //含糖量
private double vitaminAmount; //含维生素量
private double waterAmount; //含纯水量
private double totalWeight; //总重量
private double sugarRate; //含糖率
private double vitaminRate; //含维生素率
//无水果构造函数
public Juice(double totalWeight){
this.totalWeight = totalWeight;
sugarAmount = 0;
vitaminAmount = 0;
waterAmount = this.totalWeight;
sugarRate = 0;
vitaminRate = 0;
}
//苹果汁构造函数
public Juice(double totalWeight, Apple apple){
this.totalWeight = totalWeight;
sugarAmount = apple.getSugarAmount();
vitaminAmount = apple.getVitaminAmount();
waterAmount = this.totalWeight - apple.getWeight();
sugarRate = sugarAmount / this.totalWeight;
vitaminRate = vitaminAmount / this.totalWeight;
}
//梨汁构造函数
public Juice(double totalWeight, Pear pear){
this.totalWeight = totalWeight;
sugarAmount = pear.getSugarAmount();
vitaminAmount = pear.getVitaminAmount();
waterAmount = this.totalWeight - pear.getWeight();
sugarRate = sugarAmount / this.totalWeight;
vitaminRate = vitaminAmount / this.totalWeight;
}
//苹果、梨混合果汁构造函数
public Juice(double totalWeight, Apple apple, Pear pear){
this.totalWeight = totalWeight;
sugarAmount = apple.getSugarAmount() + pear.getSugarAmount();
vitaminAmount = apple.getVitaminAmount() + pear.getVitaminAmount();
waterAmount = this.totalWeight - apple.getWeight() - pear.getWeight();
sugarRate = sugarAmount / this.totalWeight;
vitaminRate = vitaminAmount / this.totalWeight;
}
//返回含糖率
public double getSugarRate(){
return sugarRate;
}
//返回含维生素率
public double getVitaminRate(){
return vitaminRate;
}
//返回含纯水量
public double getWaterAmount(){
return waterAmount;
}
//返回总重量
public double getTotalWeight(){
return totalWeight;
}
//返回含糖量
public double getSugarAmount(){
return sugarAmount;
}
//返回含维生素量
public double getVitaminAmount(){
return vitaminAmount;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -