juice.java

来自「大学java作业源程序」· Java 代码 · 共 81 行

JAVA
81
字号
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 + =
减小字号Ctrl + -
显示快捷键?