Search code examples
javabluej

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

e.g. 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?


Solution

  • These concepts may help you understand better what is wrong with your code: Java Modifiers