Nama : Riyanti Flora Manurung
NIM : 20230803138
TUGAS 5 – PEMROGRAMAN BERORIENTASI OBJECT 1. Jawaban:
public class Product { private int mProductID;
private String mProductName;
private double mPrice;
private int mQuantity;
public Product(int productID, String productName, double price, int qty) { setProduct(productID, productName, price, qty);
}
public void setProduct(int productID, String productName, double price, int qty) { mProductID = productID;
mProductName = productName;
mPrice = price;
mQuantity = qty;
}
public int getProductID() { return mProductID;
}
public String getProductName() { return mProductName;
}
public double getHarga() { return mPrice;
}
public int getQuantity() { return mQuantity;
}
public void print() {
System.out.println("ID PRODUCT: " + mProductID);
System.out.println("NAMA PRODUCT: " + mProductName);
System.out.println("HARGA: " + mPrice);
System.out.println("JUMLAH: " + mQuantity);
}
public static void main(String[] args) {
Product tBarang = new Product(0, "Aqua Botol", 5000, 10);
tBarang.print();
} } Result:
2. Jawaban:
a) Atribut/Field
private int mProductID;
private String mProductName;
private double mPrice;
private int mQuantity;
b) Konstruktor
public Product(int productID, String productName, double price, int qty) c) Fungsi Getter
public int getProductID() public String getProductName() public double getHarga() d) Fungsi Setter
public void setProduct(int productID, String productName, double price, int qty)