[Solved] Method Class Project


Read up on the return keyword. An example of getters and setters methods can be found at How do getters and setters work?. A setter method is a method which sets a variable in your class. Getter methods give the variable to whatever calls the method.

Getters:

In a main method:

String s = MethodClassProject.getBrand();

Would set String s to whatever you the brand name is.

Setters:

MethodProjectClass.setBrand("Diet Coke");

Would set the brand name to Diet Coke.

Together:

class MainWrapper {
    public static void main(String[] args) {
        MethodProjectClass.setBrand("Diet Coke");
        System.out.println(MethodProjectClass.getBrand()); // Prints Diet Coke
    }
}

I would also recommend simply making your variables public if you want the variable to be set without anything changing the input value.

I will leave the actual getter methods in the class to you, otherwise you will not learn.

solved Method Class Project