The requirements are:
✅ The program should display text on the screen.
❌The Apple class's addPrice method should not display text on the screen.
✅ The Apple class's applePrice variable must be a static int initialized to zero.
❌ The main method should call the addPrice method only twice.
❌ The Apple class's addPrice method should increase the cost of apples by the passed-in value.
However, the method does not display text on the screen, and is run only twice. It also does increase the cost of apples by the passed-in value. What is wrong with this code? Is it a bug in the requirements?
package en.codegym.task.jdk13.task04.task0402;
/*
Price of apples
*/
public class Solution {
public static void main(String[] args) {
Apple apple = new Apple();
apple.addPrice(50);
Apple apple2 = new Apple();
apple2.addPrice(100);
System.out.println("Apple price " + Apple.applePrice);
}
public static class Apple {
public static int applePrice = 0;
public void addPrice(int applePrice) {
this.applePrice += applePrice;
}
}
}
Apple.applePrice