In this program you create a new class called product with name, price and amount and a method to print it.
My Code
public class Product {
private String name;
private double price;
private int amount;
public Product(String nameAtStart, double priceAtStart, int amountAtStart){
this.amount = amountAtStart;
this.name = nameAtStart;
this.price = priceAtStart;
}
public void printProduct(){
System.out.println(this.name + ", price " + this.price + ", amount " + this.amount);
}
}
Model Code
public class Product {
private String name;
private double price;
private int amount;
public Product(String nameAtStart, double priceAtStart, int amountAtStart) {
this.name = nameAtStart;
this.price = priceAtStart;
this.amount = amountAtStart;
}
public void printProduct() {
System.out.println(this.name + ", price " + this.price + ", amount" + this.amount);
}
}
Comments
My solution and the model solution are almost exactly the same.