fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. interface Price{
  8. int getValue();
  9. void setValue(int value);
  10. }
  11.  
  12. class PrimePrice implements Price{
  13. private int value;
  14. PrimePrice(int value){
  15. this.value = value;
  16. }
  17. public int getValue(){
  18. return this.value;
  19. }
  20. public void setValue(int value){
  21. this.value = value;
  22. }
  23. }
  24.  
  25. abstract class MarginPrice implements Price{
  26. protected Price originalPrice;
  27. MarginPrice(Price price){
  28. this.originalPrice = price;
  29. }
  30. public void setValue(int value){
  31. this.originalPrice.setValue(value);
  32. }
  33. }
  34.  
  35. class WholesalePrice extends MarginPrice{
  36. private int advantage;
  37. WholesalePrice(Price price, int advantage){
  38. super(price);
  39. this.advantage = advantage;
  40. }
  41. public int getValue(){
  42. return this.originalPrice.getValue() + advantage;
  43. }
  44. }
  45.  
  46. class DoublePrice extends MarginPrice{
  47. DoublePrice(Price price){
  48. super(price);
  49. }
  50. public int getValue(){
  51. return this.originalPrice.getValue() * 2;
  52. }
  53. }
  54.  
  55. class Ideone{
  56. public static void main (String[] args) throws java.lang.Exception{
  57. Price price = new WholesalePrice(
  58. new DoublePrice(
  59. new WholesalePrice(
  60. new DoublePrice(
  61. new PrimePrice(120)
  62. )
  63. ,80
  64. )
  65. )
  66. ,200
  67. );
  68. System.out.println(price.getValue());
  69. price.setValue(100);
  70. System.out.println(price.getValue());
  71. }
  72. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
840
760