简体   繁体   中英

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();
}

eg here I want to add those aforesaid method in the main method.

How can I do that?

I add the last statement in the main method and I didn't get any Syntex error, but I'm not sure if it's correct or not.

Also how can I add the first method as well?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM