import java.util.Scanner;
public class Main {
static class Product {
private String name;
private int price;
private int stock;
public Product(String name, int price) {
this.name = name;
this.price = price;
this.stock = 0;
}
public Product(String name, int price, int stock) {
this.name = name;
this.price = price;
this.stock = stock;
}
public void addStock(int amount) {
this.stock += amount;
}
public void display() {
System.out.println("Product: " + this.name + " | Price: " + this.price + " | Stock: " + this.stock);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name1 = sc.next();
int price1 = sc.nextInt();
Product product1 = new Product(name1, price1);
String name2 = sc.next();
int price2 = sc.nextInt();
int stock2 = sc.nextInt();
Product product2 = new Product(name2, price2, stock2);
int amount = sc.nextInt();
product1.display();
System.out.println("After addStock(" + amount + "):");
product1.addStock(amount);
product1.display();
product2.display();
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: