Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. public class Item {
  2.  
  3. private String name;
  4. private int price;
  5. private String description;
  6.  
  7. public String getName() {
  8. return name;
  9. }
  10.  
  11. public int getPrice() {
  12. return price;
  13. }
  14.  
  15. public String getDescription() {
  16. return description;
  17. }
  18.  
  19. public Item(String itemName, int itemPrice, String itemDescription) {
  20. name = itemName;
  21. price = itemPrice;
  22. description = itemDescription;
  23.  
  24. }
  25.  
  26.  
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33. public class FoodItem extends Item {
  34.  
  35. public FoodItem(String itemName, int itemPrice, String itemDescription) {
  36. super(itemName, itemPrice, itemDescription);
  37. }
  38.  
  39. public void useItem() {
  40. System.out.println("You have used a food item!");
  41. }
  42.  
  43.  
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
  50. public class Medicalitem extends Item {
  51.  
  52. private boolean curesSpacePlauge;
  53.  
  54. public Medicalitem(String itemName, int itemPrice, String itemDescription, boolean curesPlague) {
  55. super(itemName, itemPrice, itemDescription);
  56. curesSpacePlauge = curesPlague;
  57. }
  58.  
  59. public boolean doesCurePlauge() {
  60. return curesSpacePlauge;
  61. }
  62.  
  63. public void useItem() {
  64. System.out.println("You have used a medical item!");
  65. }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement