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

问题描述 投票:0回答:1
/**
 * @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 bluej
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.