Answer to Question #298933 in Java | JSP | JSF for abhirami

Question #298933

1) Write a program that helps solve the following problem: ground coffee from brand A costs Rs 45 for 450 grams, while ground coffee from brand B costs Rs 47 for 500 grams. Which brand is cheaper? Create Brand class. Suggest attributes and methods that are relevant for this problem.


1
Expert's answer
2022-02-18T17:05:26-0500
public class CoffeeBrand {
    private double grams;
    private double cost;

    public CoffeeBrand(double grams, double cost) {
        this.grams = grams;
        this.cost = cost;
    }

    public double getPricePerKilo() {
        return 1000 * cost / grams;
    }

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS