如何在 main 方法中调用 setter 方法?
How can I invoke a setter method in the main method?
/**
* @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 方法中添加上述那些方法。
我该怎么做?
我在 main 方法中添加了最后一条语句,但没有出现任何 Syntex 错误,但我不确定它是否正确。
还有我怎样才能添加第一个方法?
这些概念可以帮助您更好地理解您的代码有什么问题:Java Modifiers
/**
* @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 方法中添加上述那些方法。
我该怎么做?
我在 main 方法中添加了最后一条语句,但没有出现任何 Syntex 错误,但我不确定它是否正确。
还有我怎样才能添加第一个方法?
这些概念可以帮助您更好地理解您的代码有什么问题:Java Modifiers