Hint
The constructor has the same name as the class and receives the values of all attributes: Drink(String name, String type, double volume, double price, boolean sparkling). For showing the data write the method toString().
Solution (Java)
class Drink {
String name;
String type;
double volume; // in litres
double price; // in dinars (RSD)
boolean sparkling;
// constructor with parameters
Drink(String name, String type, double volume, double price, boolean sparkling) {
this.name = name;
this.type = type;
this.volume = volume;
this.price = price;
this.sparkling = sparkling;
}
public String toString() {
return name + ", " + type + ", " + volume + " l, " + price + " RSD, sparkling: " + (sparkling ? "yes" : "no");
}
}
public class FavouriteDrink {
public static void main(String[] args) {
Drink d1 = new Drink("Lemonade", "soft drink", 0.33, 150, false);
Drink d2 = new Drink("Yogurt", "milk drink", 1.0, 180, false);
System.out.println(d1);
System.out.println(d2);
}
}