0% found this document useful (0 votes)
5 views5 pages

Oops Task

The document contains multiple Java tasks that demonstrate the creation and manipulation of Product and Account classes. Task 1 focuses on product details and total price calculation, Task 2 introduces getter and setter methods for product ID and name, Task 3 includes discount application and product display, and Task 4 manages account balance with deposit and withdrawal functionalities. Each task showcases different aspects of object-oriented programming in Java.

Uploaded by

mashudatif860
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Oops Task

The document contains multiple Java tasks that demonstrate the creation and manipulation of Product and Account classes. Task 1 focuses on product details and total price calculation, Task 2 introduces getter and setter methods for product ID and name, Task 3 includes discount application and product display, and Task 4 manages account balance with deposit and withdrawal functionalities. Each task showcases different aspects of object-oriented programming in Java.

Uploaded by

mashudatif860
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Muhammad Mashhood

2580243

Task 1:
public class Main {
public static void main(String[] args){
Product p1=new Product("pencil1",10.0,2000);
Product p2=new Product("pen",50.0,500);
[Link]("product 2 details");
[Link]();
[Link]("product 2 totalprice"+[Link]());
[Link]("\n Product 1 details: ");
[Link]();
[Link]("Product 1 totalprize"+[Link]());
}
}

public class Product {


String name;
double price;
int quantity;
Product(String name,double price,int quantity){
[Link]=name;
[Link]=quantity;
[Link]=price;

}
double calculatetotalprize() {
return price * quantity;
}
void productdetail(){
[Link]("product name"+name);
[Link]("product price"+price);
[Link]("product quantity"+quantity);
}
}
Task 2;
public class Main {
public static void main(String[] args) {
Product p1=new Product();
[Link](509764);
[Link]("product id is"+[Link]());
[Link]("pencil");
[Link]([Link]());
}
}

public class Product {


private int productid;
private String productname;

void setProductid(int pid) {


[Link] = pid;
}

int getProductid() {
return productid;
}
void setproductname(String pname) {
[Link]=pname;

}
String getProductname(){
return productname;
}
}

task 3;
class Product {

private String productId;


private String productName;
private double price;

Product(String productId, String productName, double price) {


[Link] = productId;
[Link] = productName;

if(price >= 0){


[Link] = price;
} else {
[Link] = 0;
}
}
public String getProductId() {
return productId;
}

public String getProductName() {


return productName;
}

public double getPrice() {


return price;
}

public void setProductId(String productId) {


[Link] = productId;
}

public void setProductName(String productName) {


[Link] = productName;
}

public void setPrice(double price) {


if(price >= 0){
[Link] = price;
} else {
[Link]("Price cannot be negative");
}
}

public void applyDiscount(double percentage) {


double discount = price * percentage / 100;
price = price - discount;
}

public void displayProduct() {


[Link]("Product ID: " + productId);
[Link]("Product Name: " + productName);
[Link]("Price: " + price);
}

public static void main(String[] args) {

Product p1 = new Product("P101", "Laptop", 80000);

[Link]();

[Link](10);

[Link]("After Discount:");
[Link]();
}
}

task 4;
class Account{
private int Balace;

void setBalace(int bal){


if(bal>=0){
[Link]=bal;

}
else {
[Link]("balce must be greater than o");
}
}
int getBalace(){
int balace;
return Balace;
}
void withdraw(int withdrawamount){
if (Balace>=withdrawamount){
Balace+=withdrawamount;
}

}
void deposit(int amount){
Balace+=amount;
[Link]("amount deposit sucessfully");
}
}

public class Main {


static void main(String[] args) {
Account acc1=new Account();
[Link](1000);
[Link](5000);
[Link](4000);
[Link](2000);
[Link]("balance:"+[Link]());

}
}

You might also like