/**
* @param newProfitMarginParam is used to set the gained profit margin.
*/
public void setCalculateProfitMargin(double newProfitMargin){
this.profitMargin = (this.sellingPrice - this.dealerCost) / this.sellingPrice;
}
/**
* A method to calculate the profit.
*/
public void calculateProfit(){
double dollar = this.sellingPrice - this.dealerCost;
}
public void main(String[] printDetails){
System.out.println("Jalopies Are Us Vehicle Summary:");
System.out.println("Vehicle: " + this.year + " " + this.make + " " + this.model);
System.out.println("Stock code: " + this.stockCode);
System.out.println("Dealer Cost: $" + this.dealerCost);
System.out.println("Selling Price: $" + this.sellingPrice);
System.out.println("Profit Margin: " + this.profitMargin + "%");
System.out.println("Dollare Profit: $");
calculateProfit();
}
例如这里我想在main方法中添加上述方法。
我怎样才能做到这一点?
我在主方法中添加了最后一条语句,没有收到任何 Syntex 错误,但我不确定它是否正确。
另外我怎样才能添加第一个方法?
最佳答案
这些概念可以帮助您更好地理解代码的问题:Java Modifiers
关于java - 如何在 main 方法中调用 setter 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54678795/