-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProduct.java
More file actions
23 lines (20 loc) · 896 Bytes
/
Copy pathProduct.java
File metadata and controls
23 lines (20 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class Product {
private int productId;
private String productName;
private double price;
public int getProductId() { return productId; }
public String getProductName() { return productName; }
public double getPrice() { return price; }
public void setProductId(int id) { this.productId = id; }
public void setProductName(String n) { this.productName = n; }
public void setPrice(double price) {
if (price >= 0) { this.price = price; }
else { System.out.println("Error: Price cannot be negative!"); }
}
public void displayProduct() {
System.out.println("--- Product Details ---");
System.out.println("Product ID : " + getProductId());
System.out.println("Product Name : " + getProductName());
System.out.println("Price : Rs. " + getPrice());
}
}