Created
January 17, 2020 14:08
-
-
Save mamiwinsfall93/496142efd87aafa16523f58afa0d9689 to your computer and use it in GitHub Desktop.
Price of apples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
• 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. | |
*/ | |
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("The cost of apples is " + Apple.applePrice); | |
} | |
public static class Apple { | |
public static int applePrice = 0; | |
public static void addPrice(int applePrice) { | |
Apple.applePrice= Apple.applePrice + applePrice; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment