Question

Hi I am a beginning programmer and I think I have a simple question but yet i can't find the answer. I hope you can help me:D I have four classes in total but what I need to solve is in class Person. I have a simple method that needs thePrice parameter from class Product. But it does not work because i can't get access to this parameter.

This is the method that the Person class uses to buy a product. The budget from a person has to be greater or equal to thePrice, if not > he can not buy the product. But he can only buy the product if he has not owned the product already.

public class Person{

        private String name;
        private double budget;
    private ArrayList<Product> allPossessions;
    private Product theProduct; //association with class product, I have all getters and setters etc.

    // the method:::
    public boolean Buy(Product p) {

    if (hasProduct(null) == true) {

    if (budget >= Product.getThePrice()) {    
    // getTheprice does not work, how do i get this working? How do i get this parameter from class product?

    return true;

    }

return false;

}

return false;
    }

This is class Product where I need to have thePrice, to create the method.

public abstract class Product {

    protected String Design;

    protected int yearOfPurchase;

    protected double thePrice;
}

Thank you for your time and forgive my broken english! Thank you:)

Was it helpful?

Solution

You should write a getter method for thePrice param inside Product class.

public double getPrice() {
  return thePrice;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top