如何在main方法中调用setter方法?

时间:2019-02-13 20:21:56

标签: java bluej

/**
 * @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错误,但是我不确定它是否正确。

我还如何添加第一种方法?

1 个答案:

答案 0 :(得分:1)

这些概念可以帮助您更好地理解代码的问题:Java Modifiers