Advertisement
Azazavr

com.javarush.test.level04.lesson01.task02

Jan 31st, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package com.javarush.test.level04.lesson01.task02;
  2.  
  3. /* Реализовать метод addPrice
  4. Реализовать метод addPrice(int applesPrice), чтобы при его вызове суммарная стоимость яблок увеличивалось на переданное значение.
  5. За суммарную стоимость яблок отвечает переменная public static int applesPrice.
  6. */
  7. public class Solution
  8. {
  9.     public static void main(String[] args) {
  10.         Apple apple = new Apple();
  11.         Apple.addPrice(50);
  12.         Apple apple2 = new Apple();
  13.         Apple.addPrice(100);
  14.         System.out.println("Apples price is " + Apple.applesPrice);
  15.     }
  16.  
  17.     public static class Apple{
  18.         public static int applesPrice = 0;
  19.  
  20.         public static void addPrice(int applesPrice){
  21.             Apple.applesPrice = applesPrice+Apple.applesPrice;
  22.  
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement