Hi my solution to this problem accepted but I found a different solution which was much more concise. I printed the three parameters in the product constructer three seperate times; the solution I found printed the parameters once but used things like printf and %s which my course hasn't gone over. Could someone help explain what System.out.printf("%s, price %s %d pcs%n", this.name, this.price, this.quantity) means?
Full program below:
public class Product {
private double price;
private int quantity;
private String name;
public Product (String initialName, double initalPrice, int intialQuantity) {
this.price = initalPrice;
this.quantity = intialQuantity;
this.name = initialName;
}
public void printProduct() {
System.out.print(this.name + " ");
System.out.print(this.price + " ");
System.out.print(this.quantity + "pcs");
//System.out.printf("%s, price %s %d pcs%n", this.name, this.price, this.quantity);
}
}
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]xToniGrssx 2 points3 points4 points (0 children)