fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Publication {
  8.  
  9. private String title;
  10. private String publisher;
  11. private int year;
  12. private String ident;
  13. private double price;
  14. private int quantity;
  15.  
  16. public Publication (String t, String pb, int y,String i, double pr, int q) {
  17.  
  18. title = t;
  19. publisher = pb;
  20. year = y;
  21. ident = i;
  22. price = pr;
  23. quantity = q;
  24. }
  25.  
  26. public String getTitle() {
  27. return title;
  28. }
  29.  
  30. public String getPublisher() {
  31. return publisher;
  32. }
  33.  
  34. public int getYear() {
  35. return year;
  36. }
  37.  
  38. public String getIdent() {
  39. return ident;
  40. }
  41.  
  42. public double getPrice() {
  43. return price;
  44. }
  45.  
  46. public void setPrice(double pr) {
  47. price = pr;
  48. }
  49.  
  50. public int getQuantity() {
  51. return quantity;
  52. }
  53.  
  54. public void buy(int n) {
  55. quantity += n;
  56. }
  57.  
  58. public void sell(int n) {
  59. quantity -= n;
  60. }
  61.  
  62. }
  63.  
  64. class Ideone
  65. {
  66. public static void main (String[] args) throws java.lang.Exception
  67. {
  68. Publication b = new Publication ("Psy", "Dog&Sons", 2002, "ISBN6789", 21.0, 0);
  69.  
  70. int n = 10;
  71. b.buy(n);
  72.  
  73. double koszt = n * b.getPrice();
  74.  
  75. System.out.println("Na zakup " + n + " publikacji:");
  76. System.out.println(b.getTitle());
  77. System.out.println(b.getPublisher());
  78. System.out.println(b.getYear());
  79. System.out.println(b.getIdent());
  80. System.out.println("---------------\nwydano: " + koszt);
  81.  
  82. b.sell(4);
  83. System.out.println("Po sprzedaży zostało" + b.getQuantity() + " pozycji");
  84. }
  85. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
Na zakup 10 publikacji:
Psy
Dog&Sons
2002
ISBN6789
---------------
wydano: 210.0
Po sprzedaży zostało6 pozycji