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.
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;
}
}
Comments
Leave a comment